Fully functional blogging API for AltSchool Africa blogs
Check the Project Live Url
Visit the /api-docs/
route to use swagger to explore the API
- Login:
/auth/login
using aGET
request - Logout:
/auth/logout
using aGET
request
- Install NodeJS
- Pull this repo
- Update your .env file with example.env
npm install
npm run start
npm test
- Check the
./docs
folder to get an export of my API collection from Postman or Thunder Client Collection to get the endpoints fast. - Check
localhost:<PORT>
to see the running app where PORT is specified in .env asAPI_PORT
field | data_type | constraints |
---|---|---|
id | ObjectId | required, auto_generated |
string | required, unique | |
firstName | string | required |
lastName | string | required |
password | string | required |
field | data_type | constraints |
---|---|---|
id | ObjectId | required, auto_generated |
title | string | required, unique |
description | string | |
body | string | required |
author | ObjectId | required |
state | string | required, enum: ["draft", "published"], lowercase |
read_count | number | default:0 |
reading_time | object | shape: {inNumber: number}, {inString: string} |
tags | string[] | lowercase:true |
createdAt | date | auto_generated |
updatedAt | date | auto_updated |
This is a guide on the available routes and how to use them
POST /auth/signup
{
"firstName": "Foo",
"lastName": "Bar",
"email": "foobar@gmail.com",
"password": "foobar"
}
Status: 201 Created
{
"message": "Signup successful",
"user": {
"email": "foobar@gmail.com",
"firstName": "Foo",
"lastName": "Bar",
"password": "$2b$10$GVDu6g6bKu4u6ehjY9MhxeYc8VzlaAAkO97rVOkgpYRFhFgL.nYbq",
"_id": "6367e99d0a7d3c0d68e11c3e",
"__v": 0
}
}
POST /auth/login
{
"email": "foobar@gmail.com",
"password": "foobar"
}
Status: 200 OK
{
"message": "Logged In Successfully",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiNjM2N2U5OWQwYTdkM2MwZDY4ZTExYzNlIiwiZW1haWwiOiJmb29iYXJAZ21haWwuY29tIn0sImlhdCI6MTY2Nzc1NDY1OCwiZXhwIjoxNjY3NzU4MjU4fQ.ExwC2WajQhK0S0f2vIL1BO9o9z4SD4Uz6m2uR2F9yO0"
}
POST /blogs
- Header
- Authorization: Bearer {token}
- Query Parameters
- title
- description
- body
- tags
{
"title": "My Blog 1",
"description": "Creating API Documentation",
"body": "You should be able to import API configurations for both postman and thunder client",
"tags": "api,productivity,programming"
}
Status: 201 Created
{
"status": true,
"blog": {
"title": "My Blog 1",
"description": "Creating API Documentation",
"body": "You should be able to import API configurations for both postman and thunder client",
"author": "6367ef0b0a7d3c0d68e11c44",
"state": "draft",
"read_count": 0,
"reading_time": {
"inString": "~ 4 second(s)",
"inNumber": 0.07
},
"tags": [
"api",
"productivity",
"programming"
],
"_id": "6367f13b0a7d3c0d68e11c48",
"createdAt": "2022-11-06T17:39:07.571Z",
"updatedAt": "2022-11-06T17:39:07.655Z",
"__v": 1
}
}
PATCH /blogs/publish/:id
- Header
- Authorization: Bearer {token}
Status: 200 OK
{
"status": true,
"message": "Your blog has been published!",
"blog": {
"reading_time": {
"inString": "~ 4 second(s)",
"inNumber": 0.07
},
"_id": "6367f13b0a7d3c0d68e11c48",
"title": "My Blog 1",
"description": "Creating API Documentation",
"body": "You should be able to import API configurations for both postman and thunder client",
"author": "6367ef0b0a7d3c0d68e11c44",
"state": "published",
"read_count": 0,
"tags": [
"api",
"productivity",
"programming"
],
"createdAt": "2022-11-06T17:39:07.571Z",
"updatedAt": "2022-11-06T17:49:04.544Z",
"__v": 1
}
}
GET /blogs/:id
Status: 200 OK
{
"status": true,
"blog": {
"reading_time": {
"inString": "~ 4 second(s)",
"inNumber": 0.07
},
"_id": "6367f13b0a7d3c0d68e11c48",
"title": "My Blog 1",
"description": "Creating API Documentation",
"body": "You should be able to import API configurations for both postman and thunder client",
"author": {
"email": "foobar@gmail.com",
"firstName": "Foo",
"lastName": "Bar"
},
"state": "published",
"read_count": 1,
"tags": [
"api",
"productivity",
"programming"
],
"createdAt": "2022-11-06T17:39:07.571Z",
"updatedAt": "2022-11-06T17:49:04.544Z",
"__v": 1
}
}
GET /blogs
- Query Parameters
- page (default: 1)
- orderBy (default: createdAt) other value options: reading_time and read_count. Prefix it with a
-
sign to query in descending order e.g -createdAt will arrange the blogs from the latest to the oldest - title
- author
- tags
Status: 200 OK
{
"status": true,
"count": 1,
"blogs": [
{
"reading_time": {
"inString": "~ 4 second(s)",
"inNumber": 0.07
},
"_id": "6367f13b0a7d3c0d68e11c48",
"title": "My Blog 1",
"description": "Creating API Documentation",
"body": "You should be able to import API configurations for both postman and thunder client",
"author": {
"firstName": "Foo",
"lastName": "Bar"
},
"state": "published",
"read_count": 1,
"tags": [
"api",
"productivity",
"programming"
],
"createdAt": "2022-11-06T17:39:07.571Z",
"updatedAt": "2022-11-06T17:54:01.978Z",
"__v": 1
}
]
}
GET /blogs/mine
-
Header
- Authorization: Bearer {token}
-
Query Parameters
- page (default: 1)
- state (enum: [draft, published])
Status: 200 OK
{
"status": true,
"count": 1,
"blogs": [
{
"reading_time": {
"inString": "~ 4 second(s)",
"inNumber": 0.07
},
"_id": "6367f13b0a7d3c0d68e11c48",
"title": "My Book",
"description": "It's for programmers",
"body": "You should be able to import API configurations for both postman and thunder client",
"author": "6367ef0b0a7d3c0d68e11c44",
"state": "published",
"read_count": 1,
"tags": [
"programming",
"motivation"
],
"createdAt": "2022-11-06T17:39:07.571Z",
"updatedAt": "2022-11-06T18:10:36.384Z",
"__v": 2
}
]
}
PUT /blogs/:id
-
Header
- Authorization: Bearer {token}
-
Query Parameters
- title
- description
- body
- tags
{ "title": "My Book", "description": "It's for programmers", "tags": "programming,motivation" }
Status: 200 OK
{
"status": true,
"message": "Blog edited successfully",
"blog": {
"reading_time": {
"inString": "~ 4 second(s)",
"inNumber": 0.07
},
"_id": "6367f13b0a7d3c0d68e11c48",
"title": "My Book",
"description": "It's for programmers",
"body": "You should be able to import API configurations for both postman and thunder client",
"author": "6367ef0b0a7d3c0d68e11c44",
"state": "published",
"read_count": 1,
"tags": [
"programming",
"motivation"
],
"createdAt": "2022-11-06T17:39:07.571Z",
"updatedAt": "2022-11-06T18:10:36.384Z",
"__v": 2
}
}
DELETE /blogs/:id
- Header
- Authorization: Bearer {token}
Status: 200 OK
{
"status": true,
"message": "Blog deleted successfully"
}