Skip to content

mattbushdev/nc-news-api

Repository files navigation

NC News API

Northcoders (NC) News API is a project built for the purpose of accessing application data programmatically. The intention is to mimic the building of a real world backend news service (such as reddit) which should provide this data to the front end architecture. The API is hosted through Azure App Service.

To take a look at the API endpoints and view them in action click here.

Table of contents

Built with

The technologies and packages used for this project are listed below:

Project dependencies:

Dev dependencies:

Installation

To run the API locally you will need to follow the steps below:

  1. Ensure that you have installed:
  • Node.js (download here)
  • Postgres (download here)
  1. Fork and Clone the repo
  2. Open the repo and install the dependencies by running:
    npm install

Optional

  1. In order to run the tests install the following dev dependencies:
  npm install -D jest jest-sorted supertest
  1. Run tests:
  npm test

Setting up enivronment variables

You will need to create two .env files for this project:

.env.test containing:

  DBNAME=nc_news_test

.env.development containing:

  DBNAME=nc_news

Make sure that these .env files are .gitignored.

Seeding the database

Firstly, set up the database by running:

  npm run setup-dbs

Next, set up the connection the database and seed the databases with the data by running:

  npm run seed

To get a further insight into the seeding of the database you can look in the seed.js file which contains information on the table structures, data types and foreign key references.

Complete list of endpoints

See below for a complete list of endpoints that are accessible on the server. Alternatively an overview of endpoints, descriptions and examples are provided on the /api endpoint.

    GET /api
    GET /api/topics
    GET /api/articles
    GET /api/articles/:article_id
    PATCH /api/articles/:article_id
    GET /api/articles/:article_id/comments
    POST /api/articles/:article_id/comments
    PATCH /api/comments/:comment_id
    DELETE /api/comments/:comment_id
    GET /api/users
    GET /api/users/:username

Examples

GET /api/articles/1

"article": {
        "article_id": 1,
        "author": "butter_bridge",
        "body": "I find this existence challenging",
        "created_at": "2020-07-09T20:11:00.000Z",
        "title": "Living in the shadow of a great man",
        "topic": "mitch",
        "votes": 100,
        "comment_count": "13"
      }