Skip to content

dvbenson/be_nc-news

Repository files navigation

Northcoders News API

    Project Overview



Tech: JavaScript, Express.js, Node.js, PostGresSQL

Forming the backend of a full stack web project, this API provides full CRUD capabilties using Express Router to modularise endpoints and bolster the clean, concise MVC architecture.

Although its original design has been for use with a news website, it has the versatility to be adapted to other projects such as blogs, forums and social media platforms. Within this repository is a demonstration of my proficiency in developing and implementing a user-centred API for content management and creation.

The API will also form the backend of a frontend project built in React. Its functionality covers managing news articles, users and comments. The user is able to post, update and delete articles and comments - as well as vote/downvote on articles and comments as seen on sites such as Reddit.


    API Endpoints


Users are able to access and interact with news data using the following endpoints:

GET all available endpoints

https://badsauce-webservices.onrender.com/api

GET a list of topics

https://badsauce-webservices.onrender.com/topics

POST a new topic

Construct a post request body: { slug: "Topic name here, description: "Topic description here" }
https://badsauce-webservices.onrender.com/topics

GET a list of users

https://badsauce-webservices.onrender.com/users

GET a single user by username

https://badsauce-webservices.onrender.com/users/:username

GET all articles, ordered, filtered by topic, sorted by a specified field and with pagination

https://badsauce-webservices.onrender.com/articles
https://badsauce-webservices.onrender.com/articles?limit=10&p=3
https://badsauce-webservices.onrender.com/articles?sort_by=comment_count&order=desc

POST a new article

Construct a post request body: {
                              author: "author name here",
                              title: "title of article here",
                              body: "body of post here",
                              topic: "topic name here",
                              article_img_url: "<< img url here >>"
                              }
https://badsauce-webservices.onrender.com/articles

GET & DELETE a specific article

https://badsauce-webservices.onrender.com/articles/:article_id

GET an article's comments, with pagination

https://badsauce-webservices.onrender.com/articles/:article_id/comments
https://badsauce-webservices.onrender.com/articles/:article_id/comments?limit=10&p=3

PATCH an article to vote on it

Construct a request body: { inc_votes: 1 } or { inc_votes: -1 }
https://badsauce-webservices.onrender.com/articles/:article_id

POST a new comment to a specific article

Construct a request body: {
                         username: "username here",
                         body: "body of comment goes here"
                         }
https://badsauce-webservices.onrender.com/articles

PATCH a comment to vote on it

Construct a request body: { inc_votes: 1 } or { inc_votes: -1 }
https://badsauce-webservices.onrender.com/comments/:comment_id

DELETE a comment

https://badsauce-webservices.onrender.com/comments/:comment_id

Hosted Version



Here is a live version of this app, hosted with Render.


Setup



Follow the below instructions to get yourself started.


Installation and Minimum Requirements:


  • Node.js: 19.0.0 or later
  • PostgreSQL: 12.12 or later

Cloning the repository:


In your terminal, create a directory to clone the repository into:

$ mkdir <your new directory name>

Change directory:

$ cd <your new directory name>

Clone the repository:

$ git clone https://github.com/dvbenson/Project1_news_api.git

Dependencies:


Run the below code in your terminal to install all required dependencies:

$ npm install

Dev & Test Environments:


Create two .env files:

$ touch .env.development
$ touch .env.test

Your .env.development file must contain the following line:

PGDATABASE=nc_news

Your .env.test file must contain the following line:

PGDATABASE=nc_news_test

Database setup and seeding


To setup both your development and test databases, run the following scripts:

Database Setup:

$ npm run setup-dbs

Seeding:

$ npm run seed

Testing


The jest test suite is utilised for this app. Tests can be run with the following script:

$ npm test

    Full List of Dependencies



The following Node.js packages are required for this project:


Production Dependencies


Package Version Usage
dotenv ^16.0.0 Handles environment variable files
express ^4.18.2 Routes API requests
pg ^8.7.3 Queries PostgreSQL database
pg-format ^1.0.4 Formats PostgreSQL to prevent SQL injection

Developer Dependencies


Package Version Usage
husky ^8.0.2 Validates commit by running tests before committing
jest ^27.5.1 Provides framework for testing functionality
jest-extended ^2.0.0 Adds additional jest testing identifiers
jest-sorted ^1.0.14 Adds sort testing for jest
supertest ^6.3.3 Adds simplified web request testing