Skip to main content

Blogs

API template

Tip

Ensure you have completed the configuration steps Here


Blogs can be used as a template for building new models and routes as they have all the basic REST design implemented

Get all Blogs

Request

GET
http://localhost:5501/api/v1/blog/

Response

{
"status": "String",
"results": "Number",
"data": "Array",
}

Response Validation

  1. status - response status
  1. results - Total records
  1. data - Array containing all blogs

Example

Response

{
"status": "success",
"results": 1,
"data": [
{
"_id": "62d53127f3c4488933649f7c",
"author": {
"_id": "629ad74878103d4e4a74e9e6",
"photo": "629ad74878103d4e4a74e9e6-1658134017506.jpeg",
"name": "John Doe",
"email": "user@example.com",
"identifier": "email",
"phone": "0718xxxxxxx",
"isActive": true,
"date": "2022-06-04T03:53:06.432Z",
"__v": 10,
"lastLogin": "2022-06-25T05:26:54.806Z",
"bio": "Developer"
},
"title": "NEW USER BLOG",
"body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras a bibendum massa. Nulla vulputate erat et justo aliquet, ac auctor sapien pulvinar. Nam non velit interdum, bibendum nisl vel, mollis lectus. Duis consectetur sit amet turpis ac aliquet. Suspendisse potenti. Maecenas vulputate ultricies nisl a lacinia. Suspendisse nec lobortis leo. Nam porta imperdiet bibendum. Suspendisse interdum augue rutrum justo facilisis porta nec sed leo. Ut sodales ultrices nibh, sed pulvinar sem tincidunt eu. Vivamus at ex augue. Duis dolor arcu, lobortis nec nibh quis, tempus finibus felis. Duis nec hendrerit nisi. Sed at placerat lectus. Nam orci enim, semper id tempus sit amet, venenatis volutpat lacus.",
"image": "blog-629ad74878103d4e4a74e9e6-1658138919394.jpeg",
"slug": "new-user-blog",
"date": "2022-07-18T09:53:38.040Z",
"category": "techkey",
"ratingsAverage": 4.5,
"updated": "2022-07-18T10:08:39.567Z",
"__v": 0
}
]
}

Get one user

Request

GET
http://localhost:5501/api/v1/blog/<BLOG_ID>

Response

{
"status": "String",
"data": "Object",
}

Response Validation

  1. status - response status
  1. data - User details

Example

Response

{
"status": "success",
"data": {
"_id": "62d53127f3c4488933649f7c",
"author": {
"_id": "629ad74878103d4e4a74e9e6",
"photo": "629ad74878103d4e4a74e9e6-1658134017506.jpeg",
"name": "John Doe",
"email": "user@example.com",
"identifier": "email",
"phone": "0718xxxxxxx",
"isActive": true,
"date": "2022-06-04T03:53:06.432Z",
"__v": 10,
"lastLogin": "2022-06-25T05:26:54.806Z",
"bio": "Developer"
},
"title": "NEW USER BLOG",
"body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras a bibendum massa. Nulla vulputate erat et justo aliquet, ac auctor sapien pulvinar. Nam non velit interdum, bibendum nisl vel, mollis lectus. Duis consectetur sit amet turpis ac aliquet. Suspendisse potenti. Maecenas vulputate ultricies nisl a lacinia. Suspendisse nec lobortis leo. Nam porta imperdiet bibendum. Suspendisse interdum augue rutrum justo facilisis porta nec sed leo. Ut sodales ultrices nibh, sed pulvinar sem tincidunt eu. Vivamus at ex augue. Duis dolor arcu, lobortis nec nibh quis, tempus finibus felis. Duis nec hendrerit nisi. Sed at placerat lectus. Nam orci enim, semper id tempus sit amet, venenatis volutpat lacus.",
"image": "blog-629ad74878103d4e4a74e9e6-1658138919394.jpeg",
"slug": "new-user-blog",
"date": "2022-07-18T09:53:38.040Z",
"category": "techkey",
"ratingsAverage": 4.5,
"updated": "2022-07-18T10:08:39.567Z",
"__v": 0
}
}

Add a new Blog

Request Form-Data

title: String
body: String
image: image/png, image/gif, image/jpeg
category: String

Body Validation

  1. title - blog title
  1. body - blog body
  1. image - blog image
  1. category - blog category

Request

POST
http://localhost:5501/api/v1/blog/

Response

{
"status": "String",
"data": "Object"
}

Response Validation

  1. status - request status
  1. data - user photo name

Example

Body

title: "NEW USER BLOG",
body:"Lorem ipsum dolor sit amet...."
image: selfie.png
category: "techkey",

Response

{
"status": "success",
"data": {
"_id": "62d53127f3c4488933649f7c",
"author": {
"_id": "629ad74878103d4e4a74e9e6",
"photo": "629ad74878103d4e4a74e9e6-1658134017506.jpeg",
"name": "John Doe",
"email": "user@example.com",
"identifier": "email",
"phone": "0718xxxxxxx",
"isActive": true,
"date": "2022-06-04T03:53:06.432Z",
"__v": 10,
"lastLogin": "2022-06-25T05:26:54.806Z",
"bio": "Developer"
},
"title": "NEW USER BLOG",
"body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras a bibendum massa. Nulla vulputate erat et justo aliquet, ac auctor sapien pulvinar. Nam non velit interdum, bibendum nisl vel, mollis lectus. Duis consectetur sit amet turpis ac aliquet. Suspendisse potenti. Maecenas vulputate ultricies nisl a lacinia. Suspendisse nec lobortis leo. Nam porta imperdiet bibendum. Suspendisse interdum augue rutrum justo facilisis porta nec sed leo. Ut sodales ultrices nibh, sed pulvinar sem tincidunt eu. Vivamus at ex augue. Duis dolor arcu, lobortis nec nibh quis, tempus finibus felis. Duis nec hendrerit nisi. Sed at placerat lectus. Nam orci enim, semper id tempus sit amet, venenatis volutpat lacus.",
"image": "blog-629ad74878103d4e4a74e9e6-1658138919394.jpeg",
"slug": "new-user-blog",
"date": "2022-07-18T09:53:38.040Z",
"category": "techkey",
"ratingsAverage": 4.5,
"updated": "2022-07-18T10:08:39.567Z",
"__v": 0
}
}

Update Blog

Request Form-Data

title: String
body: String
image: image/png, image/gif, image/jpeg
category: String

Body Validation

  1. title - blog title
  1. body - blog body
  1. image - blog image
  1. category - blog category

Request

PATCH
http://localhost:5501/api/v1/blog/<BLOG_ID>

Response

{
"status": "String",
"data": "Object"
}

Response Validation

  1. status - request status
  1. data - user photo name

Example

Body

title: "NEW TITLE",
body:"Lorem ipsum dolor sit amet...."
image: selfie.png
category: "techkey",

Response

{
"status": "success",
"data": {
"_id": "62d53127f3c4488933649f7c",
"author": {
"_id": "629ad74878103d4e4a74e9e6",
"photo": "629ad74878103d4e4a74e9e6-1658134017506.jpeg",
"name": "John Doe",
"email": "user@example.com",
"identifier": "email",
"phone": "0718xxxxxxx",
"isActive": true,
"date": "2022-06-04T03:53:06.432Z",
"__v": 10,
"lastLogin": "2022-06-25T05:26:54.806Z",
"bio": "Developer"
},
"title": "NEW TITLE",
"body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras a bibendum massa. Nulla vulputate erat et justo aliquet, ac auctor sapien pulvinar. Nam non velit interdum, bibendum nisl vel, mollis lectus. Duis consectetur sit amet turpis ac aliquet. Suspendisse potenti. Maecenas vulputate ultricies nisl a lacinia. Suspendisse nec lobortis leo. Nam porta imperdiet bibendum. Suspendisse interdum augue rutrum justo facilisis porta nec sed leo. Ut sodales ultrices nibh, sed pulvinar sem tincidunt eu. Vivamus at ex augue. Duis dolor arcu, lobortis nec nibh quis, tempus finibus felis. Duis nec hendrerit nisi. Sed at placerat lectus. Nam orci enim, semper id tempus sit amet, venenatis volutpat lacus.",
"image": "blog-629ad74878103d4e4a74e9e6-1658138919394.jpeg",
"slug": "new-user-blog",
"date": "2022-07-18T09:53:38.040Z",
"category": "techkey",
"ratingsAverage": 4.5,
"updated": "2022-07-18T10:08:39.567Z",
"__v": 0
}
}

Delete Blog

Request

DELETE
http://localhost:5501/api/v1/blog/<BLOG_ID>

Response


Response Validation

Empty response


Example

Response