Skip to content

Blog Post API Back End, With User Authentication using JWT

License

Notifications You must be signed in to change notification settings

clubcleaver/blogpostapi

Repository files navigation

BLOG POST API

End Points

API End Points are broken down in three different sections according to functionality logic, So they remain relatable.

  1. user
  2. posts
  3. comment
REST Full, excerpt:
** USER **
POST /user/register - // Register User
POST /user/login - //Login User

** POSTS **
GET /posts -  // Get All
GET /posts/:PostId - //Get One
POST /posts - // Submit Post
PATCH /posts - // Edit only Post
DELETE /posts - // Delete Post including Comments

** COMMENTS **
POST /comment - // Submit Comment on Post
DELETE /Comment - // Delete Comment on Post

Details

Paths to API EndPoints are listed below according to represented functionality.

USER

REGISTER Path: /user/register Mehod: POST Content Type: JSON JSON Fields Required in request body:

{
  "username": "<Username>",
  "email": "<[email protected]>", //sanitised
  "password": "<password>" //minimum 6 characters
}

Returns:

{
"success": true/false,
"message": "<message>"
}

LOGIN Path: /user/login Mehod: POST Content Type: JSON Required in request body:

{
"email": "<email@address>",
"password": "<password>"
}

Returns: Auth-Token in Token

{
"success": true/false,
"message": "<message>",
"Token": "String" // If Success: true
}

POSTS

GET ALL Path: /posts Mehod: GET Requirements: NONE Returns:

[
  {
    "_id": "String(ObjectId)", //Post ID
    "author": {
      "_id": "String(ObjectId)", //User ID
      "username": "<username>",
      "__v": 0
    },
    "date": "Doth DATE YEAR", //date submitted
    "category": ["String", "String"],
    "post": "String(POST)",
    "comments": [
      {
      "_id": "String(ObjectId)", //Comment ID
      "author": "<username>".
      "comment": "Doth DATE YEAR" //date submitted
      }
    ],
    "__v": 10 //times updated
  },
  ...
]

GET ONE Path: /posts/:postid Mehod: GET Requirements: NONE Returns:

[
  {
    "_id": "String(ObjectId)", //Post ID
    "author": {
      "_id": "String(ObjectId)", //User ID
      "username": "<username>",
      "__v": 0
    },
    "date": "Doth DATE YEAR", //date submitted
    "category": ["String", "String"],
    "post": "String(POST)",
    "comments": [
      {
      "_id": "String(ObjectId)", //Comment ID
      "author": "<username>",
      "comment": "Doth DATE YEAR" //date submitted
      }
    ],
    "__v": 10 //times updated
  },
]

SUBMIT - Authenticated Path: /posts Mehod: POST Content Type: JSON Required in request body:

{
  "category": "TEST",
  "post": {"New Post"},
}

Required in Auth. Header: Auth Token //Required

Returns:

{
"success": true / false,
"message": "<message>",
}

*EDIT - Authenticated - POST Owner Path: /posts Mehod: PATCH Content Type: JSON Required in request body:

{
  "postId": "String(ObjectId)",
  "post": "<Edited Post>",
}

Required in Auth. Header: Auth Token //Required

Returns:

{
"success": false, // Only if Fails
"message": "<message>",
"post": {'Updated Post'} // If Success: true
}

DELETE - Authenticated - POST Owner Path: /posts Mehod: DELETE Content Type: JSON Required in request body:

{
  "postId": "String(ObjectId)",
}

Required in Auth. Header: Auth Token //Required

Returns:

{
"success": true / false,
"message": "<message>",
}

COMMENTS

SUMBIT - Authenticated Path: /comment Mehod: POST Content Type: JSON Required in request body:

{
  "postId": "String(ObjectId)",
  "comment": "<New Comment>"
}

Required in Auth. Header: Auth Token //Required

Returns:

{
"success": true / false,
"message": "<message>",
"post": {"<Updated Post>"}
}

DELETE - Authenticated - POST Owner Path: /comment Mehod: DELETE Content Type: JSON Required in request body:

{
  "postId": "String(ObjectId)",
  "commentId": "String(ObjectId)",
}

Required in Auth. Header: Auth Token //Required

Returns:

{
"success": true / false,
"message": "<message>",
}

About

Blog Post API Back End, With User Authentication using JWT

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published