Skip to content

AngelosGR21/backend-nc-news

Repository files navigation

Northcoders News API


Summary

This API mimics the build of a real world backend service that contains different articles, topics, comments and users. It provides full CRUD functionality and was built using TDD with Jest as the testing framework.
The main backend framework used for the routes is Express and for the database PSQL which was installed using the PG npm package.

Below i will provide a brief overview of all the routes available and what they do. ( The endpoints are also available to see in JSON format in the file of this directory "endpoints.json" or you can view them live here : View endpoints )

GET routes

  • /api/users ----> Returns an array of objects of all the users available

  • /api/users/:username ----> Returns an object with the details of the user found

  • /api/topics ----> Returns an array of objects of all the topics available

  • /api ----> Returns an object with keys representing all the routes available for usage as well as examples of responses

  • /api/articles ----> Returns an array of objects of all the articles available (queries available for this endpoint : author, topic, sort_by, order)

  • /api/articles/:article_id ----> Returns an object with the article found

  • /api/articles/:article_id/comments ----> Returns an array of objects of all the comments associated to the article specified

POST routes

  • /api/topics ----> Returns the created topic. Fields required >>slug: String, description: String || Coming soon

  • /api/articles ----> Returns the created article. Fields required >> author: String -> Needs to be the username from the users table, title: String, body: String, (topic: String -> Needs to be the slug from the topics table)

  • /api/articles/:article_id/comments ----> Returns the created comment on the article given. Fields required >> username: String -> Needs to be the username from the users table, body: String

PATCH routes

  • /api/articles/:article_id ----> Returns the updated article. Fields required >> inc_votes : Number (It will increment the votes, but if you pass a negative number it will subtract)

  • /api/comments/:comment_id ----> Returns the updated comment. Fields required >> inc_votes : Number (It will increment the votes, but if you pass a negative number it will subtract)

DELETE routes

  • /api/comments/:comment_id ----> Returns status code 204

  • /api/articles/:article_id ----> Returns status code 204 || Coming soon


You can also see all the additional packages used for the API beneath


Setup

To run this app in your local machine please follow the next steps

  1. In your terminal paste this command >> git clone https://github.com/AngelosGR21/BC-News-Project-Northcoders-.git to clone the repository in your system.

  2. Make sure you run npm install to install all dependencies needed.

  3. After all dependencies have been installed run the command npm run setup-dbs to create the databases.

  4. Next to seed the databases run :

    • npm run seed for the development data
    • npm run seedTestData for the test data
  5. Before you run the tests you need to create a .env file in the root of your project

  6. After you created the .env file you need to update it with the variables from .env-example

  1. You're all set, all that's left is to run the tests!
    • npm test

Minimum Versions Needed

  • Node : 17.6.0
  • PSQL : 12.10

About

API built with Node, Express and PSQL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published