NC News API

API Routes

GET /api

GET /api

Description

serves up a json representation of all the available endpoints of the api.

GET /api/topics

GET /api/topics

Description

serves an array of all topics.

Example Response

{
  "topics": [{ "slug": "football", "description": "Footie!" }]
}

GET /api/articles

GET /api/articles

Description

serves an array of all articles, sorted by date descending by default. Accepts below query parameters.

Queries

[
  {
    "sort_by": "Sorts the articles by any valid column (defaults to created_at).",
    "order": "Orders the articles in 'asc' or 'desc' order (defaults to 'desc').",
    "topic": "Filters the articles by the specified topic."
  }
]

Example Response

{
  "articles": [
    {
      "title": "Seafood substitutions are increasing",
      "topic": "cooking",
      "author": "weegembump",
      "created_at": "2018-05-30T15:59:13.341Z",
      "votes": 0,
      "comment_count": 6
    }
  ]
}

GET /api/users

GET /api/users

Description

serves an array of all users.

Example Response

{
  "username": "johndoe",
  "name": "John Doe",
  "avatar_url": "https://example.com/avatar.jpg"
}

GET /api/users/:username

GET /api/users/:username

Description

serves a single user object by their username.

Example Response

{
  "user": {
    "username": "butter_bridge",
    "avatar_url": "https://www.healthytherapies.com/wp-content/uploads/2016/06/Lime3.jpg",
    "name": "jonny"
  }
}

GET /api/articles/:article_id

GET /api/articles/:article_id

Description

serves an article object by its ID.

Example Response

{
  "article": {
    "article_id": 1,
    "title": "Running a Node App",
    "topic": "coding",
    "author": "jessjelly",
    "body": "This is part two of a series on how to get up and running with Systemd and Node.js. This part dives deeper into how to successfully run your app with systemd long-term, and how to set it up in a production environment.",
    "created_at": "2020-11-07T06:03:00.000Z",
    "votes": 0,
    "article_img_url": "https://images.pexels.com/photos/11035380/pexels-photo-11035380.jpeg?w=700&h=700",
    "comment_count": 11
  }
}

GET /api/articles/:article_id/comments

GET /api/articles/:article_id/comments

Description

serves an array of comments for the given article_id.

Example Response

[
  {
    "comment_id": 272,
    "votes": 17,
    "created_at": "2020-10-21T05:05:00.000Z",
    "author": "tickle122",
    "body": "Distinctio excepturi laboriosam eos aperiam quis amet eum animi minima. Officiis in quia. Est consequatur optio atque nostrum iusto impedit harum quod asperiores.",
    "article_id": 33
  }
]

POST /api/articles/:article_id/comments

POST /api/articles/:article_id/comments

Description

Adds a comment for the given article_id

Example Request

{
  "body": {
    "username": "butter_bridge",
    "body": "Great post!"
  }
} 

Example Response

{
  "comment": {
    "comment_id": 12,
    "votes": 0,
    "created_at": "2020-06-01T00:00:00.000Z",
    "author": "butter_bridge",
    "body": "Great post!",
    "article_id": 1
  }
}

PATCH /api/articles/:article_id

PATCH /api/articles/:article_id

Description

Updates an article's vote count

Example Request

{
  "inc_votes": -100
}

Example Response

{
  "article": {
    "article_id": 1,
    "title": "Seafood substitutions are increasing",
    "topic": "cooking",
    "author": "weegembump",
    "body": "...",
    "created_at": "2018-05-30T15:59:13.341Z",
    "votes": -100,
    "article_img_url": "https://..."
  }
}

DELETE /api/comments/:comment_id

DELETE /api/comments/:comment_id

Description

Deletes a comment by its comment_id and responds with 204 No Content

Example Response

No body returns for response