Giter Site home page Giter Site logo

blogapi's Introduction

My Awesome Blog API Documentation

API Base URL

The API is accessible at https://blog-api-vlasandrei-com.onrender.com.

Authentication

The following routes require authentication using JWT (JSON Web Token) in the request headers:

  • POST /articles/ (Create a new article)
  • PUT /articles/:articleId (Update an article)
  • DELETE /articles/:articleId (Delete an article)

For these routes, include the JWT token in the request headers as follows: Authorization: Bearer

Create a New Article

  • Endpoint: POST /articles/
  • Description: Create a new article.
  • Request Body:
    • title (string): The title of the article.
    • content (string): The content of the article.
    • published (boolean): The published status of the article.
  • Response:
    • 200 OK: Success message: "Article "{title}" successfully created!"
    • 400 Bad Request: Error message: "The title of the article is already used."

Update an Article

  • Endpoint: PUT /articles/:articleId
  • Description: Update an existing article.
  • Request Parameters:
    • articleId (string): The ID of the article to update.
  • Request Body:
    • title (string): The updated title of the article.
    • content (string): The updated content of the article.
    • published (boolean): The updated published status of the article.
  • Response:
    • 200 OK: Success message: "Article {title} updated with success."

Delete an Article

  • Endpoint: DELETE /articles/:articleId
  • Description: Delete an article.
  • Request Parameters:
    • articleId (string): The ID of the article to delete.
  • Response:
    • 200 OK: Success message: "Article deleted."

Get All Articles

  • Endpoint: GET /articles/
  • Description: Get all articles with filtering, sorting, and pagination options.
  • Request Query Parameters:
    • page (optional, integer): The page number for pagination.
    • pageSize (optional, integer): The number of articles per page.
    • sort (optional, string): The sort order ("asc" or "desc") for articles.
    • before (optional, date): Filter articles created before a specific date.
    • after (optional, date): Filter articles created after a specific date.
  • Response:
    • 200 OK: List of articles.

Get an Article by ID

  • Endpoint: GET /articles/:articleId
  • Description: Get an article by its ID.
  • Request Parameters:
    • articleId (string): The ID of the article.
  • Response:
    • 200 OK: Article details.
    • 404 Not Found: Error message: "Resource not found."

Note: Replace :articleId in the endpoints with the actual ID of the article.

BlogAPI - Comment Feature

This is the documentation for the comment feature of the BlogAPI. The comment feature allows users to post, update, and delete comments on articles.

Comment Controller

postComment

Creates a new comment for an article.

  • Method: POST
  • Route: /:articleId/comments
  • Middleware: validateCommentBody, confirmValidation

Request Body:

{
  "author": "John Doe",
  "content": "This is a comment",
  "parentCommentId": "optional-parent-comment-id"
}

Response:

Status: 200 (OK)
Body: JSON object containing the created comment

updateComment

Updates an existing comment.

Method: PUT
Route: /:articleId/comments/:commentId
Middleware: validateCommentBody, confirmValidation

Request Body:

{
  "authorId": "comment-author-id",
  "content": "Updated comment content"
}

Response:

Status: 200 (OK)
Body: JSON object with a success message

deleteComment

Deletes an existing comment.

Method: DELETE
Route: /:articleId/comments/:commentId
Middleware: validateCommentToDelete, confirmValidation

Request Body:

{
"authorId": "comment-author-id"
}

Response:

Status: 200 (OK)
Body: Success message

Comment Routes

The following routes are available for managing comments:

POST /:articleId/comments: Create a new comment for an article
PUT /:articleId/comments/:commentId: Update an existing comment
DELETE /:articleId/comments/:commentId: Delete an existing comment

Validation Middleware validateCommentBody

Validates the request body of the comment-related routes.

author: The name of the comment author (string, 2-20 characters)
commentId (route parameter): The ID of the comment (string)
content: The content of the comment (string, 3-2000 characters)
parentComment (optional): The ID of the parent comment if it is a reply (string)

validateCommentToDelete

Validates the request body and route parameters for deleting a comment.

authorId: The ID of the comment author (string, required)
commentId: The ID of the comment to be deleted (string, required)

blogapi's People

Contributors

bigvl avatar

Watchers

 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.