This is an api for a Blog app
- User should be able to sign up
- User should be able to and sign in to the blog app with passport authentication strategy token which expires after 1 hour
- Users should have a first_name, last_name, email, password when signing up and - email and password to sign in
- Logged in and not logged in users should be able to get a list of published blogs created
- Logged in and not logged in users should be able to to get a published blog
- A blog can be in two states; draft and published
- Logged in users should be able to create a blog.
- When a blog is created, it is in draft state
- The owner of the blog should be able to update the state of the blog to published
- The owner of a blog should be able to edit the blog in draft or published state
- The owner of the blog should be able to delete the blog in draft or published state
- The owner of the blog should be able to get a list of their blogs.
- It should be filterable by state
- Blogs created should have title, description, tags, author, timestamp, state, read_count, reading_time and body.
- The list of blogs endpoint that can be accessed by both logged in and not logged in users should be paginated, default it to 20 blogs per page.
- It is also searchable by author, title and tags.
- It is also orderable by read_count, reading_time and timestamp
- When a single blog is requested, the api should return the user information(the author) with the blog. The read_count of the blog too should be updated by 1
- joi input validation
- helmet security
- express rate limiter
- Good logging
- Install NodeJS, mongodb
- pull this repo
- update env with example.env
- run
npm start
- blog-api-5ecs.onrender.com
field | data_type | constraints |
---|---|---|
string | required, unique | |
first_name | string | required |
last_name | string | required |
password | string | required |
field | data_type | constraints |
---|---|---|
title | string | required , unique |
description | string | |
author | mongoose.Types.ObjectId | ref:'User' |
state | string | enum: ['Draft','Published'] |
tags | string | |
body | string | required |
- Route: /auth/signup
- Method: POST
- Body:
{
"first_name": "eri",
"last_name": "Ogunseye",
"email": "eri@gmail.com",
"password": "secret"
}
- Responses
Success
{
"user": {
"first_name": "eri",
"last_name": "Ogunseye",
"email": "eri@gmail.com",
"password": "$2b$10$n4DlouV0ucabGCXHQ5gKeeyPO/ar8Gyzygqf.3Qi3.fK8pfQD8WdG",
"_id": "636678b7283f52463dde032f",
"__v": 0
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNjM2Njc4YjcyODNmNTI0NjNkZGUwMzJmIiwiZW1haWwiOiJlcmlAZ21haWwuY29tIiwiZnVsbG5hbWUiOiJlcmkgT2d1bnNleWUiLCJpYXQiOjE2Njc2NTk5NTksImV4cCI6MTY2ODI2NDc1OX0.JWDLGOAkCtIAKmd1nR6Yr4RPZCoz5fwZ3Xy3JEy5yA4",
"message": "account succesfully created"
}
- Route: auth/login
- Method: POST
- Body:
{
"email": "eri@gmail.com",
"password": "secrett"
}
- Responses
Success
{
"user": {
"user": {
"_id": "636678b7283f52463dde032f",
"first_name": "eri",
"last_name": "Ogunseye",
"email": "eri@gmail.com",
"password": "$2b$10$n4DlouV0ucabGCXHQ5gKeeyPO/ar8Gyzygqf.3Qi3.fK8pfQD8WdG",
"__v": 0
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNjM2Njc4YjcyODNmNTI0NjNkZGUwMzJmIiwiZW1haWwiOiJlcmlAZ21haWwuY29tIiwiZnVsbG5hbWUiOiJlcmkgT2d1bnNleWUiLCJpYXQiOjE2Njc2NjAzNTEsImV4cCI6MTY2ODI2NTE1MX0.YDKr40xcVslPKOM_ZHSS9d-JmBvCVAGjfkQ0af_O26c"
},
"message": "Login successful"
}
- Route: /blog/all
- Method: GET
- Query params:
- page (default: 1)
- per_page (default: 20)
- order_by (default: createdAt)
- order_by ('read_count' for asc, '-read_count' for desc)
- author
- title
- tags
- Responses
Success
{
status: true,
blog:[]
}
- Route: /blog/all/:id
- Method: GET
- Responses
Success
{
"status": true,
"blog": {
"_id": "636685f9e392c6cf8c087d6a",
"title": "manchester city",
"description": "king of pass ",
"author": {
"_id": "6364f7f02d071da00221cb76",
"first_name": "logo",
"last_name": "semilogo",
"email": "logo@gmail.com",
"__v": 0
},
"writtenBy": "logo semilogo",
"state": "Published",
"read_count": 1,
"reading_time": "0.168 minutes",
"tags": "football",
"body": "hi, history of football is beig said here ",
"createdAt": "2022-11-05T15:49:13.054Z",
"updatedAt": "2022-11-05T15:49:43.984Z",
"__v": 0
}
}
- Route: /user/blog/create
- Method: POST
- Header
- Authorization: Bearer {token}
- Body:
{
"title":"testing new routes",
"description":"not much to say",
"state":"Published",
"tags":"sense",
"body":"omo, i have nothing to say to you do your worse"
}
- Responses
Success
{
"status": true,
"blog": {
"title": "testing new routes",
"description": "not much to say",
"author": "6364f7f02d071da00221cb76",
"writtenBy": "logo semilogo",
"state": "Published",
"read_count": 0,
"reading_time": "0.188 minutes",
"tags": "sense",
"body": "omo, i have nothing to say to you do your worse",
"_id": "63659f18d3e7a0b702d0cad9",
"createdAt": "2022-11-04T23:24:08.768Z",
"updatedAt": "2022-11-04T23:24:08.768Z",
"__v": 0
}
}
- Route: /user/blog/published
- Method: GET
- Header:
- Authorization: Bearer {token}
- Query params:
- page (default: 1)
- per_page (default: 20)
- order_by (default: createdAt)
- order_by ('read_count' for asc, '-read_count' for desc)
- author
- title
- tags
- Responses
Success
{
status: true,
blog:[]
}
- Route: /user/blog/published/:id
- Method: GET
- Header
- Authorization: Bearer {token}
- Responses
Success
{
"status": true,
"blog": {
"_id": "636685f9e392c6cf8c087d6a",
"title": "manchester city",
"description": "king of pass ",
"author": {
"_id": "6364f7f02d071da00221cb76",
"first_name": "logo",
"last_name": "semilogo",
"email": "logo@gmail.com",
"__v": 0
},
"writtenBy": "logo semilogo",
"state": "Published",
"read_count": 1,
"reading_time": "0.168 minutes",
"tags": "football",
"body": "hi, history of football is beig said here ",
"createdAt": "2022-11-05T15:49:13.054Z",
"updatedAt": "2022-11-05T15:49:43.984Z",
"__v": 0
}
}
- Route: /user/blog/all
- Method: GET
- Header:
- Authorization: Bearer {token}
- Query params:
- page (default: 1)
- per_page (default: 5)
- state (Draft, Published)
- Responses
Success
{
status: true,
blog:[]
}
- Route: /user/blog/all/:id
- Method: GET
- Header
- Authorization: Bearer {token}
- Responses
Success
{
"status": true,
"blog": {
"_id": "636685f9e392c6cf8c087d6a",
"title": "manchester city",
"description": "king of pass ",
"author": {
"_id": "6364f7f02d071da00221cb76",
"first_name": "logo",
"last_name": "semilogo",
"email": "logo@gmail.com",
"__v": 0
},
"writtenBy": "logo semilogo",
"state": "Published",
"read_count": 1,
"reading_time": "0.168 minutes",
"tags": "football",
"body": "hi, history of football is beig said here ",
"createdAt": "2022-11-05T15:49:13.054Z",
"updatedAt": "2022-11-05T15:49:43.984Z",
"__v": 0
}
}
- Route: /user/blog/all/:id
- Method: patch
- Header
- Authorization: Bearer {token}
- Body:
{
"state": "Published"
}
- Responses
Success
{
"status": true,
"blog": {
"_id": "636685f9e392c6cf8c087d6a",
"title": "manchester city",
"description": "king of pass ",
"author": {
"_id": "6364f7f02d071da00221cb76",
"first_name": "logo",
"last_name": "semilogo",
"email": "logo@gmail.com",
"__v": 0
},
"writtenBy": "logo semilogo",
"state": "Published",
"read_count": 1,
"reading_time": "0.168 minutes",
"tags": "football",
"body": "hi, history of football is beig said here ",
"createdAt": "2022-11-05T15:49:13.054Z",
"updatedAt": "2022-11-05T15:49:43.984Z",
"__v": 0
}
}
- Route: /user/blog/all/:id
- Method: delete
- Header
- Authorization: Bearer {token}
- Responses
Success
{
"status": true,
"blog": {
"acknowledged": true,
"deletedCount": 1
}
}
...
- Ademeso Josiah