{
  "sectionSubTitles": [
    { "description": "Description" },
    { "query-params": "Query Parameters" },
    { "req-body": "Request Body" },
    { "res-body": "Response Body" },
    { "status-codes": "Status Codes & Error Handling" }
  ],
  "sections": [
    {
      "anchor": "get-all-articles",
      "method": "GET",
      "endpoint": "/api/articles",
      "description": "This endpoint lists all available articles from the database. The list is paginated with a 10 item per page limit by default.",
      "queryParams": [
        {
          "example": "sortBy=[column]",
          "description": "Sort articles by column"
        },
        { "example": "order=[asc/desc]", "description": "Sorting order" },
        {
          "example": "topic=[slag]",
          "description": "Filter articles by topic"
        },
        {
          "example": "limit=[number]",
          "description": "Limit parameter defines the number of items returned in a single request. Set to 10 by default."
        },
        {
          "example": "p=[number]",
          "description": "P parameter stands for page, defines which page to start from in the current request. Starts from 1."
        }
      ],
      "reqBody": "N/A",
      "resBody": {
        "articles": [
          {
            "article_id": "[number]",
            "title": "[string]",
            "topic": "[string]",
            "author": "[string]",
            "body": "[string]",
            "created_at": "[string]",
            "votes": "[number]",
            "article_img_url": "[string]",
            "comment_count": "[number as a string]"
          }
        ],
        "total_count": "[number]"
      },
      "statusCodes": [
        {
          "type": "success",
          "code": "200",
          "title": "OK",
          "description": "Responds with an array on the key of articles."
        },
        {
          "type": "error",
          "code": "400",
          "title": "Bad Request Error",
          "description": "Sort by column does not exist or not allowed (eg. body)."
        },
        {
          "type": "error",
          "code": "400",
          "title": "Bad Request Error",
          "description": "Incorrect \"order\" key. Must be asc or dec."
        },
        {
          "type": "error",
          "code": "400",
          "title": "Invalid Type Error",
          "description": "Parameter 'p' must be a number!"
        },
        {
          "type": "error",
          "code": "400",
          "title": "Invalid Type Error",
          "description": "Limit must be a number!"
        },
        {
          "type": "error",
          "code": "404",
          "title": "Not Found Error",
          "description": "Filtered topic does not exist."
        },
        {
          "type": "error",
          "code": "404",
          "title": "Not Found Error",
          "description": "Requested page [num] exceded page count! Occurs when p query parameter is set to higher than the max page count."
        }
      ]
    },
    {
      "anchor": "get-article-by-id",
      "method": "GET",
      "endpoint": "/api/articles/:article_id",
      "description": "This endpoint lists a specified article from the database.",

      "reqBody": "N/A",
      "resBody": {
        "article": {
          "comment_count": "[number as a string]",
          "article_id": "[number]",
          "title": "[string]",
          "topic": "[string]",
          "author": "[string]",
          "body": "[string]",
          "created_at": "[string]",
          "votes": "[number]",
          "article_img_url": "[string]"
        }
      },
      "statusCodes": [
        {
          "type": "success",
          "code": "200",
          "title": "OK",
          "description": "Article fetched succesfully"
        },
        {
          "type": "error",
          "code": "404",
          "title": "Not Found",
          "description": "Article not found under the specified ID."
        },
        {
          "type": "error",
          "code": "400",
          "title": "Invalid Type Error",
          "description": "Incorrect article id format. Must be a number."
        }
      ]
    },
    {
      "anchor": "get-comments-of-article",
      "method": "GET",
      "endpoint": "/api/articles/:article_id/comments",
      "description": "This endpoint lists all comments of a specified article from the database. The list is paginated with a 10 item per page limit by default.",
      "reqBody": "N/A",
      "resBody": {
        "comments": [
          {
            "comment_id": "[number]",
            "article_id": "[number]",
            "body": "[string]",
            "votes": "[number]",
            "author": "[string]",
            "created_at": "[string]"
          }
        ],
        "total_count": "[number]"
      },
      "queryParams": [
        {
          "example": "limit=[number]",
          "description": "Limit parameter defines the number of items returned in a single request. Set to 10 by default."
        },
        {
          "example": "p=[number]",
          "description": "P parameter stands for page, defines which page to start from in the current request. Starts from 1."
        }
      ],
      "statusCodes": [
        {
          "type": "success",
          "code": "200",
          "title": "OK",
          "description": "Responds with an array on the key of articles."
        },
        {
          "type": "error",
          "code": "404",
          "title": "Not Found Error",
          "description": "Article not found under the specified ID."
        },
        {
          "type": "error",
          "code": "404",
          "title": "Not Found Error",
          "description": "No comments found at the specified article."
        },
        {
          "type": "error",
          "code": "400",
          "title": "Invalid Type Error",
          "description": "Incorrect article id format. Must be a number."
        },
        {
          "type": "error",
          "code": "400",
          "title": "Invalid Type Error",
          "description": "Parameter 'p' must be a number!"
        },
        {
          "type": "error",
          "code": "400",
          "title": "Invalid Type Error",
          "description": "Limit must be a number!"
        },
        {
          "type": "error",
          "code": "404",
          "title": "Not Found Error",
          "description": "Requested page [num] exceded page count! Occurs when p query parameter is set to higher than the max page count."
        }
      ]
    },
    {
      "anchor": "post-comment-to-article",
      "method": "POST",
      "endpoint": "/api/articles/:article_id/comments",
      "description": "This endpoint posts a new comment to a specified article, and returns the posted comment object in the response body.",
      "reqBody": { "username": "[string]", "body": "[string max-length:500]" },
      "resBody": {
        "comment_id": "[number]",
        "article_id": "[number]",
        "body": "[string]",
        "votes": "[number]",
        "author": "[string]",
        "created_at": "[string]"
      },
      "statusCodes": [
        {
          "type": "success",
          "code": "201",
          "title": "OK",
          "description": "Responds with an object on the key of comment."
        },
        {
          "type": "error",
          "code": "404",
          "title": "Not Found Error",
          "description": "Article not found!"
        },
        {
          "type": "error",
          "code": "404",
          "title": "Not Found Error",
          "description": "Username does not exist!"
        },
        {
          "type": "error",
          "code": "400",
          "title": "Invalid Type Error",
          "description": "Incorrect article id format!"
        },
        {
          "type": "error",
          "code": "400",
          "title": "Bad Request Error",
          "description": "Comment is required!"
        },
        {
          "type": "error",
          "code": "400",
          "title": "Bad Request Error",
          "description": "Comment is too long. It must be less than 500 characters!"
        }
      ]
    },
    {
      "anchor": "patch-article-vote",
      "method": "PATCH",
      "endpoint": "/api/articles/:article_id",
      "description": "This endpoint updated the votes for a specified article, and returns the updated article object in the response body.",
      "reqBody": { "inc_votes": "[integer]" },
      "resBody": {
        "article": {
          "comment_count": "[number as a string]",
          "article_id": "[number]",
          "title": "[string]",
          "topic": "[string]",
          "author": "[string]",
          "created_at": "[string]",
          "votes": "[number]",
          "article_img_url": "[string]"
        }
      },
      "statusCodes": [
        {
          "type": "success",
          "code": "200",
          "title": "OK",
          "description": "Responds with an object on the key of article."
        },
        {
          "type": "error",
          "code": "404",
          "title": "Not Found Error",
          "description": "Article not found!"
        },
        {
          "type": "error",
          "code": "400",
          "title": "Invalid Type Error",
          "description": "Incorrect article id format!"
        },
        {
          "type": "error",
          "code": "400",
          "title": "Invalid Key",
          "description": "Invalid key in the response body. It must be 'inc_votes'."
        },
        {
          "type": "error",
          "code": "400",
          "title": "Invalid Value",
          "description": "Invalid value in the response body. It must be a number either positive or negative."
        }
      ]
    },
    {
      "anchor": "update-comment-vote",
      "method": "PATCH",
      "endpoint": "/api/comments/:comment_id",
      "description": "This endpoint updates the votes of a specified comment.",
      "reqBody": { "inc_votes": "integer" },
      "resBody": {
        "comment": {
          "comment_id": "[number]",
          "article_id": "[number]",
          "body": "[string]",
          "votes": "[number]",
          "author": "[string]",
          "created_at": "[string]"
        }
      },
      "statusCodes": [
        {
          "type": "success",
          "code": "200",
          "title": "OK",
          "description": "Comment successfully updated. It returns the updated comment object."
        },
        {
          "type": "error",
          "code": "400",
          "title": "Invalid Type Error",
          "description": "Incorrect comment ID format. Must be a number!"
        },
        {
          "type": "error",
          "code": "400",
          "title": "Invalid Type Error",
          "description": "Incorrect or missing incrementation amount in the body. Must be a number!"
        },
        {
          "type": "error",
          "code": "404",
          "title": "Not Found Error",
          "description": "Comment not found"
        },
        {
          "type": "error",
          "code": "404",
          "title": "Not Found Error",
          "description": "User not found"
        },
        {
          "type": "error",
          "code": "422",
          "title": "Not Found Error",
          "description": "Missing username"
        }
      ]
    },
    {
      "anchor": "delete-comment",
      "method": "DELETE",
      "endpoint": "/api/comments/:comment_id",
      "description": "This endpoint deletes a specified comment.",
      "reqBody": "N/A",
      "resBody": "N/A",
      "statusCodes": [
        {
          "type": "success",
          "code": "204",
          "title": "OK",
          "description": "Sucessful deletion of a comment."
        },
        {
          "type": "error",
          "code": "400",
          "title": "Invalid Type Error",
          "description": "Incorrect comment ID format. Must be a number!"
        },
        {
          "type": "error",
          "code": "404",
          "title": "Not Found Error",
          "description": "Comment not found"
        }
      ]
    },
    {
      "anchor": "get-all-topics",
      "method": "GET",
      "endpoint": "/api/topics",
      "description": "This endpoint lists all available topics from the database.",
      "reqBody": "N/A",
      "resBody": {
        "topics": [
          {
            "slug": "[string]",
            "description": "[string]",
            "img_url": "[string]"
          }
        ]
      },
      "statusCodes": [
        {
          "type": "success",
          "code": "200",
          "title": "OK",
          "description": "Responds with an array on the key of topics."
        }
      ]
    },
    {
      "anchor": "get-all-users",
      "method": "GET",
      "endpoint": "/api/users",
      "description": "This endpoint lists all users from the database.",
      "reqBody": "N/A",
      "resBody": {
        "topics": [
          {
            "username": "[string]",
            "name": "[string]",
            "avatar_url": "[string]"
          }
        ]
      },
      "statusCodes": [
        {
          "type": "success",
          "code": "200",
          "title": "OK",
          "description": "Responds with an array on the key of users."
        }
      ]
    },
    {
      "anchor": "get-user-by-username",
      "method": "GET",
      "endpoint": "/api/users/:username",
      "description": "This endpoint returns a specified user from the database.",

      "reqBody": "N/A",
      "resBody": {
        "user": {
          "username": "[string]",
          "name": "[string]",
          "avatar_url": "[string]"
        }
      },
      "statusCodes": [
        {
          "type": "success",
          "code": "200",
          "title": "OK",
          "description": "User fetched succesfully"
        },
        {
          "type": "error",
          "code": "404",
          "title": "Not Found",
          "description": "User not found by the specified username."
        }
      ]
    },
    {
      "anchor": "post-new-article",
      "method": "POST",
      "endpoint": "/api/articles",
      "description": "This endpoint posts a new article and returns the newly posted article object.",
      "reqBody": {
        "author": "[string]",
        "title": "[string, 255 max length]",
        "body": "[string, 600 max length]",
        "topic": "[string]",
        "article_img_url": "[string]"
      },
      "resBody": {
        "article": {
          "comment_count": "[number as a string]",
          "article_id": "[number]",
          "title": "[string]",
          "topic": "[string]",
          "author": "[string]",
          "body": "[string]",
          "created_at": "[string]",
          "votes": "[number]",
          "article_img_url": "[string]"
        }
      },
      "statusCodes": [
        {
          "type": "success",
          "code": "201",
          "title": "OK",
          "description": "Responds with an object on the key of article."
        },
        {
          "type": "error",
          "code": "404",
          "title": "Not Found Error",
          "description": "Occurs if author or topic missing from request body, or does not exist in database."
        },
        {
          "type": "error",
          "code": "400",
          "title": "Bad Request Error",
          "description": "Occurs if title or body is missing from the request body, or the request body is missing."
        },
        {
          "type": "error",
          "code": "400",
          "title": "Bad Request Error",
          "description": "Article body or title is too long. Body must be no more than 600 and title no more than 255 character!"
        }
      ]
    },
    {
      "anchor": "post-new-topic",
      "method": "POST",
      "endpoint": "/api/topics",
      "description": "This endpoint posts a new topic and returns the newly posted topic object.",
      "reqBody": {
        "description": "[string, 255 max length]",
        "slug": "[string, 55 max length]",
        "article_img_url": "[string]"
      },
      "resBody": {
        "article": {
          "description": "[string]",
          "slug": "[string]",
          "img_url": "[string]"
        }
      },
      "statusCodes": [
        {
          "type": "success",
          "code": "201",
          "title": "OK",
          "description": "Responds with an object on the key of article."
        },
        {
          "type": "error",
          "code": "404",
          "title": "Not Found Error",
          "description": "Occurs if author or topic missing from request body, or does not exist in database."
        },
        {
          "type": "error",
          "code": "400",
          "title": "Bad Request Error",
          "description": "Occurs if title or body is missing from the request body, or the request body is missing."
        },
        {
          "type": "error",
          "code": "400",
          "title": "Bad Request Error",
          "description": "Topic description or slug is too long. Description must be no more than 255 and slug no more than 55 character!"
        }
      ]
    }
  ]
}
