This is an api for a blog app built as an exam project from AltSchool Africa.
-
Users should have a first_name, last_name, email and password.
-
A user should be able to sign up and sign in into the blog app.
-
Use JWT as an authentication strategy and expire the token after 1 hour.
-
A blog can be in two states; draft and published.
-
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
-
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.
-
The endpoint should be paginated.
-
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 should also be searchable by author, title and tags.
-
It should also be 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.
-
Come up with any algorithm for calculating the reading_time of the blog.
-
Write tests for all endpoints.
- Install Node.js, MongoDB
- Install project dependencies
- clone this repo
- update env with example.env
- run
npm run start:dev
git clone https://github.com/adeyinkaoresanya/griot.git
npm install
npm run start:dev
field | data_type | constraints |
---|---|---|
id | string | required |
first_name | string | required |
last_name | string | required |
username | string | optional |
author_name | string | derived |
string | required, unique | |
password | string | required |
blogs | ref - Blog |
field | data_type | constraints |
---|---|---|
title | string | required |
description | string | required |
content | string | required |
state | string | required, default: 'draft', enum: ['draft', 'published'] |
read_count | Number | default: 0 |
tags | array | optional |
reading_time | Number | |
author | ref - User | |
postedAt (timestamp) |
- Route: /register
- Method: POST
- Body
{
"first_name": "Jane",
"last_name": "Bakes",
"username": "janebakes",
"email": "janebakes@gmail.com",
"password": "janebakes236"
}
Response
{"first_name":"Jane",
"last_name":"Bakes",
"username":"janebakes",
"email":"janebakes@gmail.com"}
- Route: /login
- Method: POST
Body
{
"username": "janebakes",
"password": "janebakes236"
}
Response
{
"username": "janebakes",
"token": { token }
}
- Route: /write
- Method: POST
- Header
- Authorization: {token}
Body
{
"title": "The Paper Girl",
"description": "Coming of age story",
"content": "Lorem ipsum dolor sit amet. Aut ipsum doloremque eum consequatur illum in sint totam qui porro minima eos corrupti dolorum nam velit atque quo quibusdam quidem. Et dicta dicta ut consequatur corrupti est consequatur quia est enim ratione aut fugit nemo. Aut dolor Quis id nihil voluptatibus ut illo dolores sit expedita aspernatur rem consectetur cumque est odio officia sed rerum enim. Nam quas porro qui placeat architecto non natus labore vel eaque dicta quo consequatur ipsum "
}
Response
{
"newBlog": {
"title": "The Paper Girl",
"description": "Coming of age story",
"content": "Lorem ipsum dolor sit amet. Aut ipsum doloremque eum consequatur illum in sint totam qui porro minima eos corrupti dolorum nam velit atque quo quibusdam quidem. Et dicta dicta ut consequatur corrupti est consequatur quia est enim ratione aut fugit nemo. Aut dolor Quis id nihil voluptatibus ut illo dolores sit expedita aspernatur rem consectetur cumque est odio officia sed rerum enim. Nam quas porro qui placeat architecto non natus labore vel eaque dicta quo consequatur ipsum ",
"author": "636823d1655ac68d6e234c04",
"state": "draft",
"read_count": 0,
"tags": [],
"postedAt": "Sun Nov 06 2022 22:29:15 GMT+0100 (West Africa Standard Time)",
"_id": "6368273dc2d2c0ad8b2f757c",
"reading_time": 1,
"__v": 0
}
}
- Route: /edit:id
- Method: PUT
- Header
- Authorization: Bearer {token}
Body
{
"title": "Gone girl",
"description": "Same story",
"content": "Lorem ipsum dolor sit amet. Aut ipsum doloremque eum consequatur illum in sint totam qui porro minima eos corrupti dolorum nam velit atque quo quibusdam quidem. Et dicta dicta ut consequatur corrupti est consequatur quia est enim ratione aut fugit nemo. Aut dolor Quis id nihil voluptatibus ut illo dolores sit laceat architecto non natus labore vel eaque dicta quo consequatur ipsum "
}
Response
{
{
"updatedBlog": {
"title": "Gone Girl",
"description": "Same story",
"content": "Lorem ipsum dolor sit amet. Aut ipsum doloremque eum consequatur illum in sint totam qui porro minima eos corrupti dolorum nam velit atque quo quibusdam quidem. Et dicta dicta ut consequatur corrupti est consequatur quia est enim ratione aut fugit nemo. Aut dolor Quis id nihil voluptatibus ut illo dolores sit laceat architecto non natus labore vel eaque dicta quo consequatur ipsum "
"author": "636823d1655ac68d6e234c04",
"state": "draft",
"read_count": 0,
"tags": [],
"postedAt": "Sun Nov 06 2022 22:29:15 GMT+0100 (West Africa Standard Time)",
"_id": "6368273dc2d2c0ad8b2f757c",
"reading_time": 1,
"__v": 0
}
}
}
- Adeyinka Oresanya