Blogs

Blog post management

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
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": "[email protected]",
        "role": "user",
        "firstName": "text",
        "lastName": "text",
        "socialLinks": {
          "website": "text",
          "facebook": "text",
          "instagram": "text",
          "linkedin": "text",
          "x": "text",
          "youtube": "text"
        },
        "createdAt": "2025-07-28T18:23:29.495Z",
        "updatedAt": "2025-07-28T18:23:29.495Z"
      },
      "viewsCount": 0,
      "likesCount": 0,
      "commentsCount": 0,
      "status": "draft",
      "publishedAt": "2025-07-28T18:23:29.495Z",
      "updatedAt": "2025-07-28T18:23:29.495Z"
    }
  ]
}

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
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": "[email protected]",
      "role": "user",
      "firstName": "text",
      "lastName": "text",
      "socialLinks": {
        "website": "text",
        "facebook": "text",
        "instagram": "text",
        "linkedin": "text",
        "x": "text",
        "youtube": "text"
      },
      "createdAt": "2025-07-28T18:23:29.495Z",
      "updatedAt": "2025-07-28T18:23:29.495Z"
    },
    "viewsCount": 0,
    "likesCount": 0,
    "commentsCount": 0,
    "status": "draft",
    "publishedAt": "2025-07-28T18:23:29.495Z",
    "updatedAt": "2025-07-28T18:23:29.495Z"
  }
}

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
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": "[email protected]",
        "role": "user",
        "firstName": "text",
        "lastName": "text",
        "socialLinks": {
          "website": "text",
          "facebook": "text",
          "instagram": "text",
          "linkedin": "text",
          "x": "text",
          "youtube": "text"
        },
        "createdAt": "2025-07-28T18:23:29.495Z",
        "updatedAt": "2025-07-28T18:23:29.495Z"
      },
      "viewsCount": 0,
      "likesCount": 0,
      "commentsCount": 0,
      "status": "draft",
      "publishedAt": "2025-07-28T18:23:29.495Z",
      "updatedAt": "2025-07-28T18:23:29.495Z"
    }
  ]
}

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
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": "[email protected]",
      "role": "user",
      "firstName": "text",
      "lastName": "text",
      "socialLinks": {
        "website": "text",
        "facebook": "text",
        "instagram": "text",
        "linkedin": "text",
        "x": "text",
        "youtube": "text"
      },
      "createdAt": "2025-07-28T18:23:29.495Z",
      "updatedAt": "2025-07-28T18:23:29.495Z"
    },
    "viewsCount": 0,
    "likesCount": 0,
    "commentsCount": 0,
    "status": "draft",
    "publishedAt": "2025-07-28T18:23:29.495Z",
    "updatedAt": "2025-07-28T18:23:29.495Z"
  }
}

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
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": "[email protected]",
      "role": "user",
      "firstName": "text",
      "lastName": "text",
      "socialLinks": {
        "website": "text",
        "facebook": "text",
        "instagram": "text",
        "linkedin": "text",
        "x": "text",
        "youtube": "text"
      },
      "createdAt": "2025-07-28T18:23:29.495Z",
      "updatedAt": "2025-07-28T18:23:29.495Z"
    },
    "viewsCount": 0,
    "likesCount": 0,
    "commentsCount": 0,
    "status": "draft",
    "publishedAt": "2025-07-28T18:23:29.495Z",
    "updatedAt": "2025-07-28T18:23:29.495Z"
  }
}

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.
delete
DELETE /api/v1/blogs/{blogId} HTTP/1.1
Host: blog-api.codewithsadee.com
Authorization: Bearer JWT
Accept: */*

No content

Was this helpful?