Git Product home page Git Product logo

be-nc-news-sprint's Introduction

Northcoders News API

Link to project on Heroku

This api has many endpoints allowing access to northcoders news.

Getting started

These instructions will get you a copy of the project up and running on your local machine.

Prerequisites

The minimum version of node you will need to run this app is v12.11.1

Installing

Clone this repo:

git clone https://github.com/Hy-M/be-nc-news-sprint

cd be-nc-news-sprint

Install the dependencies:

npm i

In the 'db' folder, create a file called credentials.js to store your psql credentials:

exports.username = "yourusername";
exports.password = "yourpassword";

Set up the development and test databases :

npm run setup-dbs

Seed the development database:

npm run seed

Run the app. It will run on http://localhost:9090

npm start

To view all of the available endpoints in JSON format, make a GET /api request.

Testing

To run tests on the endpoints, type the following in your terminal:

npm test

To run tests on the util functions:

npm test-utils

API endpoints

The following endpoints are available:

GET /api/topics

GET /api/users/:username

GET /api/articles/:article_id
PATCH /api/articles/:article_id

POST /api/articles/:article_id/comments
GET /api/articles/:article_id/comments

GET /api/articles

PATCH /api/comments/:comment_id
DELETE /api/comments/:comment_id

GET /api

More specifically, each endpoint responds like this:

GET /api/topics

Responds with

  • an array of topic objects, each of which should have the following properties:
    • slug
    • description

GET /api/users/:username

Responds with

  • a user object which should have the following properties:
    • username
    • avatar_url
    • name

GET /api/articles/:article_id

Responds with

  • an article object, which should have the following properties:

    • author which is the username from the users table
    • title
    • article_id
    • body
    • topic
    • created_at
    • votes
    • comment_count which is the total count of all the comments with this article_id - you should make use of knex queries in order to achieve this

PATCH /api/articles/:article_id

Request body accepts

  • an object in the form { inc_votes: newVote }

    • newVote will indicate how much the votes property in the database should be updated by

    e.g.

    { inc_votes : 1 } would increment the current article's vote property by 1

    { inc_votes : -100 } would decrement the current article's vote property by 100

Responds with

  • the updated article

POST /api/articles/:article_id/comments

Request body accepts

  • an object with the following properties:
    • username
    • body

Responds with

  • the posted comment

GET /api/articles/:article_id/comments

Responds with

  • an array of comments for the given article_id of which each comment should have the following properties:
    • comment_id
    • votes
    • created_at
    • author which is the username from the users table
    • body

Accepts queries

  • sort_by, which sorts the comments by any valid column (defaults to created_at)
  • order, which can be set to asc or desc for ascending or descending (defaults to descending)

GET /api/articles

Responds with

  • an articles array of article objects, each of which should have the following properties:
    • author which is the username from the users table
    • title
    • article_id
    • topic
    • created_at
    • votes
    • comment_count which is the total count of all the comments with this article_id - you should make use of knex queries in order to achieve this

Should accept queries

  • sort_by, which sorts the articles by any valid column (defaults to date)
  • order, which can be set to asc or desc for ascending or descending (defaults to descending)
  • author, which filters the articles by the username value specified in the query
  • topic, which filters the articles by the topic value specified in the query

PATCH /api/comments/:comment_id

Request body accepts

  • an object in the form { inc_votes: newVote }

    • newVote will indicate how much the votes property in the database should be updated by

    e.g.

    { inc_votes : 1 } would increment the current comments's vote property by 1

    { inc_votes : -1 } would decrement the current comments's vote property by 1

Responds with

  • the updated comment

DELETE /api/comments/:comment_id

Should

  • delete the given comment by comment_id

Responds with

  • status 204 and no content

GET /api

Responds with

  • JSON describing all the available endpoints

Built using

  • Node.js
  • Express.js
  • PostgreSQL
  • Node postgres
  • Knex.js
  • Mocha
  • Chai
  • Chai-sorted
  • Supertest

Author

Humayraa Mulla

be-nc-news-sprint's People

Contributors

hy-m avatar anthonymedina avatar nc-paul-rogerson avatar anatdean avatar tomosim avatar p-copley avatar sssam-c avatar alexander-cox avatar daviidbartlett avatar antariess avatar nicola-20 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.