NC News Docs API
A robust backend API for a Reddit-style news platform, built with Node.js and Express. This project provides comprehensive article, topic, user, and comment management functionality. This was built as part of the Northcoders bootcamp and makes up the final project for the backend module
API Topics
GET /api/topics
Description: Serves an array of all topics.
Queries: None
Example Response:
{
"topics": [
{
"slug": "football",
"description": "Footie!"
}
]
}
Articles
GET /api/articles
Description: serves an array of all articles
Queries: sort_by, order, topics, limit, p
Example Response:
{
"articles": [
{
"article_id": "2",
"title": "Seafood substitutions are increasing",
"topic": "cooking",
"author": "weegembump",
"created_at": "2018-05-30T15:59:13.341Z",
"votes": 0,
"article_img_url": "imager.hello_test",
"comment_count": 6
}
]
}
GET /api/articles/:article_id
Description: Retrieves a single article by ID with comment count
Example Response:
{
"article": {
"article_id": 1,
"title": "Example Article Title",
"body": "This is the article content...",
"votes": 10,
"topic": "technology",
"author": "johndoe",
"created_at": "2023-01-01T12:00:00.000Z",
"comment_count": 5,
"article_img_url": "https://example.com/image.jpg"
}
}
Error Responses:
404 Not Found: { "message": "Article not found" }
400 Bad Request: { "message": "Invalid article ID" }
Example Usage:
fetch('/api/articles/3')
.then(response => response.json())
.then(data => console.log(data));
POST /api/articles
Description: Posts a new article
Example Response:
{
"article": [
{
"article_id": "17",
"title": "How to make proper ramen",
"topic": "cooking",
"author": "Jiro",
"created_at": "2018-05-30T15:59:13.341Z",
"votes": 0,
"article_img_url": "imager.hello_test",
"comment_count": 0
}
]
}
Error Responses:
400 Bad Request: { "message": "Missing required fields (title, body, author, topic)" }
404 Not Found: { "message": "Author or topic not found" }
PATCH /api/articles/:article_id
Description: Updates the vote count of an article by the specified amount.
Example Patch:
{
"inc_votes": 1
}
Example Response:
{
"updatedArticle": {
"article_id": 2,
"title": "Seafood substitutions are increasing",
"topic": "cooking",
"author": "weegembump",
"body": "Text of the article...",
"created_at": "2018-05-30T15:59:13.341Z",
"votes": 1,
"article_img_url": "imager.hello_test"
}
}
Users
GET /api/users
Description: serves an array of all users
Example Response:
{
"users": [
{
"username": "pookie1",
"name": "Blumpf Barton",
"avatar_url": "https://mrbean.fandom.com/wiki/Mr._Bean_Wiki?file=Mr_beans_holiday_ver2.jpg"
}
]
}
GET /api/users/:username
Description: serves an object of user by specified username
Example Response:
{
"user": {
"username": "pookie1",
"name": "Blumpf Barton",
"avatar_url": "https://mrbean.fandom.com/wiki/Mr._Bean_Wiki?file=Mr_beans_holiday_ver2.jpg"
}
}
Comments
GET /api/articles/:article_id/comments
Description: serves an array of all comments for article id
Queries: limit (default 10), p (page number)
Example Response:
Error Responses:
POST /api/articles/:article_id/comments
Description: posts a comment via article ID
Example Request Body:
Example Response:
Error Responses:
PATCH /api/comments/:comment_id
Description: Updates the vote count of a comment by the specified amount.
Example Request Body:
Example Response:
DELETE /api/comments/:comment_id
Description: Deletes comment at comment id.
Example Response: