馃摌
Blog API
  • Documentation
  • API References
  • Root
  • Authentication
  • Users
  • Blogs
  • Likes
  • Comments
  • Models
Powered by GitBook

漏 2025 codewithsadee

On this page

Was this helpful?

Export as PDF

Blogs

PreviousUsersNextLikes

Was this helpful?

Blog post management

Get Blogs by User

get

Retrieves a paginated list of blogs by a specific user. Admins see all; users see only 'published'. Sorted by creation date descending.

Authorizations
Path parameters
userIdstring 路 objectidRequired

ID of the user.

Query parameters
limitinteger 路 min: 1 路 max: 50Optional

Maximum number of items to return.

Default: 20
offsetintegerOptional

Number of items to skip for pagination.

Default: 0
Responses
200
A list of blogs by the specified user.
application/json
400
Invalid input data provided. See errors object for details.
application/json
401
Authentication information is missing or invalid (e.g., missing/expired token).
application/json
500
An unexpected error occurred on the server.
application/json
get
GET /api/v1/blogs/user/{userId} HTTP/1.1
Host: blog-api.codewithsadee.com
Authorization: Bearer JWT
Accept: */*
{
  "limit": 1,
  "offset": 1,
  "total": 1,
  "blogs": [
    {
      "_id": "text",
      "title": "text",
      "slug": "text",
      "content": "text",
      "banner": {
        "url": "text",
        "width": 1,
        "height": 1
      },
      "author": {
        "_id": "text",
        "username": "text",
        "email": "name@gmail.com",
        "role": "user",
        "firstName": "text",
        "lastName": "text",
        "socialLinks": {
          "website": "text",
          "facebook": "text",
          "instagram": "text",
          "linkedin": "text",
          "x": "text",
          "youtube": "text"
        },
        "createdAt": "2025-06-07T16:44:29.914Z",
        "updatedAt": "2025-06-07T16:44:29.914Z"
      },
      "viewsCount": 0,
      "likesCount": 0,
      "commentsCount": 0,
      "status": "draft",
      "publishedAt": "2025-06-07T16:44:29.914Z",
      "updatedAt": "2025-06-07T16:44:29.914Z"
    }
  ]
}

Get Blog by Slug

get

Retrieves a single blog post by its unique slug. Regular users cannot view 'draft' posts.

Authorizations
Path parameters
slugstringRequired

Slug of the blog post.

Responses
200
The requested blog post.
application/json
400
Invalid input data provided. See errors object for details.
application/json
401
Authentication information is missing or invalid (e.g., missing/expired token).
application/json
403
Access denied due to insufficient permissions.
application/json
404
The specified resource was not found.
application/json
500
An unexpected error occurred on the server.
application/json
get
GET /api/v1/blogs/{slug} HTTP/1.1
Host: blog-api.codewithsadee.com
Authorization: Bearer JWT
Accept: */*
{
  "blog": {
    "_id": "text",
    "title": "text",
    "slug": "text",
    "content": "text",
    "banner": {
      "url": "text",
      "width": 1,
      "height": 1
    },
    "author": {
      "_id": "text",
      "username": "text",
      "email": "name@gmail.com",
      "role": "user",
      "firstName": "text",
      "lastName": "text",
      "socialLinks": {
        "website": "text",
        "facebook": "text",
        "instagram": "text",
        "linkedin": "text",
        "x": "text",
        "youtube": "text"
      },
      "createdAt": "2025-06-07T16:44:29.914Z",
      "updatedAt": "2025-06-07T16:44:29.914Z"
    },
    "viewsCount": 0,
    "likesCount": 0,
    "commentsCount": 0,
    "status": "draft",
    "publishedAt": "2025-06-07T16:44:29.914Z",
    "updatedAt": "2025-06-07T16:44:29.914Z"
  }
}

Delete Blog Post (Admin)

delete

Deletes a blog post by ID. Also removes banner. Admin role required (route security).

Authorizations
Path parameters
blogIdstring 路 objectidRequired

ID of the blog post.

Responses
204
Request successful, no response body.
401
Authentication information is missing or invalid (e.g., missing/expired token).
application/json
403
Access denied due to insufficient permissions.
application/json
404
The specified resource was not found.
application/json
500
An unexpected error occurred on the server.
application/json
delete
DELETE /api/v1/blogs/{blogId} HTTP/1.1
Host: blog-api.codewithsadee.com
Authorization: Bearer JWT
Accept: */*

No content

  • GETGet All Blogs
  • POSTCreate Blog Post (Admin)
  • GETGet Blogs by User
  • GETGet Blog by Slug
  • PUTUpdate Blog Post (Admin)
  • DELETEDelete Blog Post (Admin)

Get All Blogs

get

Retrieves a paginated list of blogs. Admins see all; users see only 'published'. Sorted by creation date descending.

Authorizations
Query parameters
limitinteger 路 min: 1 路 max: 50Optional

Maximum number of items to return.

Default: 20
offsetintegerOptional

Number of items to skip for pagination.

Default: 0
Responses
200
A list of blogs.
application/json
400
Invalid input data provided. See errors object for details.
application/json
401
Authentication information is missing or invalid (e.g., missing/expired token).
application/json
500
An unexpected error occurred on the server.
application/json
get
GET /api/v1/blogs/ HTTP/1.1
Host: blog-api.codewithsadee.com
Authorization: Bearer JWT
Accept: */*
{
  "limit": 1,
  "offset": 1,
  "total": 1,
  "blogs": [
    {
      "_id": "text",
      "title": "text",
      "slug": "text",
      "content": "text",
      "banner": {
        "url": "text",
        "width": 1,
        "height": 1
      },
      "author": {
        "_id": "text",
        "username": "text",
        "email": "name@gmail.com",
        "role": "user",
        "firstName": "text",
        "lastName": "text",
        "socialLinks": {
          "website": "text",
          "facebook": "text",
          "instagram": "text",
          "linkedin": "text",
          "x": "text",
          "youtube": "text"
        },
        "createdAt": "2025-06-07T16:44:29.914Z",
        "updatedAt": "2025-06-07T16:44:29.914Z"
      },
      "viewsCount": 0,
      "likesCount": 0,
      "commentsCount": 0,
      "status": "draft",
      "publishedAt": "2025-06-07T16:44:29.914Z",
      "updatedAt": "2025-06-07T16:44:29.914Z"
    }
  ]
}

Create Blog Post (Admin)

post

Creates a new blog post. Requires banner image upload. Admin role required.

Authorizations
Body
titlestring 路 max: 180Required
contentstringRequired

HTML content

statusstring 路 enumOptionalDefault: draftPossible values:
banner_imagestring 路 binaryRequired

Banner image file (png/jpg/webp, max 2MB)

Responses
201
Blog post created successfully.
application/json
400
Invalid input data provided. See errors object for details.
application/json
401
Authentication information is missing or invalid (e.g., missing/expired token).
application/json
403
Access denied due to insufficient permissions.
application/json
413
Uploaded file exceeds size limit.
application/json
500
An unexpected error occurred on the server.
application/json
post
POST /api/v1/blogs/ HTTP/1.1
Host: blog-api.codewithsadee.com
Authorization: Bearer JWT
Content-Type: multipart/form-data
Accept: */*
Content-Length: 74

{
  "title": "text",
  "content": "text",
  "status": "draft",
  "banner_image": "binary"
}
{
  "blog": {
    "_id": "text",
    "title": "text",
    "slug": "text",
    "content": "text",
    "banner": {
      "url": "text",
      "width": 1,
      "height": 1
    },
    "author": {
      "_id": "text",
      "username": "text",
      "email": "name@gmail.com",
      "role": "user",
      "firstName": "text",
      "lastName": "text",
      "socialLinks": {
        "website": "text",
        "facebook": "text",
        "instagram": "text",
        "linkedin": "text",
        "x": "text",
        "youtube": "text"
      },
      "createdAt": "2025-06-07T16:44:29.914Z",
      "updatedAt": "2025-06-07T16:44:29.914Z"
    },
    "viewsCount": 0,
    "likesCount": 0,
    "commentsCount": 0,
    "status": "draft",
    "publishedAt": "2025-06-07T16:44:29.914Z",
    "updatedAt": "2025-06-07T16:44:29.914Z"
  }
}

Update Blog Post (Admin)

put

Updates an existing blog post. Banner update optional. Admin role required (route security).

Authorizations
Path parameters
blogIdstring 路 objectidRequired

ID of the blog post.

Body
titlestring 路 max: 180Optional
contentstringOptional

HTML content

statusstring 路 enumOptionalPossible values:
banner_imagestring 路 binaryOptional

New banner image file (png/jpg/webp, max 2MB)

Responses
200
Blog post updated successfully.
application/json
400
Invalid input data provided. See errors object for details.
application/json
401
Authentication information is missing or invalid (e.g., missing/expired token).
application/json
403
Access denied due to insufficient permissions.
application/json
404
The specified resource was not found.
application/json
413
Uploaded file exceeds size limit.
application/json
500
An unexpected error occurred on the server.
application/json
put
PUT /api/v1/blogs/{blogId} HTTP/1.1
Host: blog-api.codewithsadee.com
Authorization: Bearer JWT
Content-Type: multipart/form-data
Accept: */*
Content-Length: 74

{
  "title": "text",
  "content": "text",
  "status": "draft",
  "banner_image": "binary"
}
{
  "blog": {
    "_id": "text",
    "title": "text",
    "slug": "text",
    "content": "text",
    "banner": {
      "url": "text",
      "width": 1,
      "height": 1
    },
    "author": {
      "_id": "text",
      "username": "text",
      "email": "name@gmail.com",
      "role": "user",
      "firstName": "text",
      "lastName": "text",
      "socialLinks": {
        "website": "text",
        "facebook": "text",
        "instagram": "text",
        "linkedin": "text",
        "x": "text",
        "youtube": "text"
      },
      "createdAt": "2025-06-07T16:44:29.914Z",
      "updatedAt": "2025-06-07T16:44:29.914Z"
    },
    "viewsCount": 0,
    "likesCount": 0,
    "commentsCount": 0,
    "status": "draft",
    "publishedAt": "2025-06-07T16:44:29.914Z",
    "updatedAt": "2025-06-07T16:44:29.914Z"
  }
}