Blog Post API is a post management demonstration application with CRUD functionality.
- Node Js
- Type Script
- Frameworks (express, mongoose, mongoose-paginate-v2, jsonwebtoken, jest)
- Install packages:
npm install(be sure that in your env have installed the Node JS) - Run Mongo Database Container:
docker-compose up(be sure that you have) installed Docker Desktop for your system) - Run Node Application:
npm start
- Install packages:
npm install(be sure that in your env have installed the Node JS) - Run Mongo Database Container:
docker-compose up(be sure that you have) installed Docker Desktop for your system) - Run all tests
npm test
- Create a new user post
- POST http://localhost:3003/api/v1/user
- Request Body
{ "username": "Hayk Hovhannisyanm", "password": "asdf@2023", "email" :"haik.hovhanisyan@gmail.com", "role": "ADMIN" } - Response Body
{ "username": "Hayk Hovhannisyanm", "email": "haik.hovhanisyan@gmail.com", "password": "$2b$10$Lxm5z.fRgo5hdKt8GwvWi..dQ4erBiArxKkckmKBjlWhU44aZjbBq", "role": "ADMIN", "id": "64e9caad35da4570341ddf0c" }
- Request Body
- POST http://localhost:3003/api/v1/user
- Login with a new user post
- POST http://localhost:3003/api/v1/login
- Request Body
{ "username": "Hayk Hovhannisyan", "password": "asdf@2023" }- Response Body
{ "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoiSGF5ayBIb3ZoYW5uaXN5YW4iLCJpYXQiOjE2OTMwNzczNjAsImV4cCI6MTY5MzA3ODI2MH0.Qp-Mnh288XyEIAiNBEnitu-j7mw_Q7BjjiRoO_Gw3Dc", "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoiSGF5ayBIb3ZoYW5uaXN5YW4iLCJpYXQiOjE2OTMwNzczNjAsImV4cCI6MTY5MzA3ODU2MH0.pLNRbT1AkydBvBmYgFnC630ignj1xbS3HHJ8Mpq46b8" }
- POST http://localhost:3003/api/v1/login
- Create a new blog post
- POST http://localhost:3003/api/v1/posts
- HEADERS: Authorization: Bearer {access_token}
- Request Body
{ "title": "Post Title", "content": "Post Content", "author" :"Postianus Contentus" } - Response Body
{ "title": "Post Title", "content": "Post Content", "author": "Postianus Contentus", "createdAt": "2023-08-25T18:56:08.321Z", "id": "64e8f9487b164140e9d6a82b" }
- Request Body
- Update an existing blog post
- POST http://localhost:3003/api/v1/posts/64e8f9487b164140e9d6a82b
- HEADERS: Authorization: Bearer {access_token}
- Request Body
{ "title": "Post Title Updated", "content": "Post Content Updated", "author" :"Postianus Contentus Updated" } - Response Body
{ "title": "Post Title Updated", "content": "Post Content Updated", "author": "Postianus Contentus Updated", "createdAt": "2023-08-25T18:56:08.321Z", "id": "64e8f9487b164140e9d6a82b" }
- Request Body
- Retrieve a single blog post by its ID
- GET http://localhost:3003/api/v1/posts/64e8f9487b164140e9d6a82b
- Response Body
{ "title": "Post Title Updated", "content": "Post Content Updated", "author": "Postianus Contentus Updated", "createdAt": "2023-08-25T18:56:08.321Z", "id": "64e8f9487b164140e9d6a82b" }
- Response Body
- GET http://localhost:3003/api/v1/posts/64e8f9487b164140e9d6a82b
- Retrieve all blog posts
- GET http://localhost:3003/api/v1/posts
- Response Body
[ { "title":"Post Title Updated", "content":"Post Content Updated", "author":"Postianus Contentus Updated", "createdAt":"2023-08-25T18:56:08.321Z", "id":"64e8f9487b164140e9d6a82b" }, { "title": "Post Title 2", "content": "Post Content 2", "author": "Postianus Contentus 2", "createdAt": "2023-08-25T19:15:33.437Z", "id": "64e8fdd518f09d1c5f0b426f" } ]
- Response Body
- GET http://localhost:3003/api/v1/posts
- Retrieve all with limit and page
- GET http://localhost:3003/api/v1/posts?page=1&limit=2
- Response Body
[ { "title": "Post Title 3", "content": "Post Content 3", "author": "Postianus Contentus 3", "createdAt": "2023-08-25T19:30:32.249Z", "id": "64e901583af0474c85144d90" }, { "title": "Post Title", "content": "Post Content", "author": "Postianus Contentus", "createdAt": "2023-08-25T19:30:24.046Z", "id": "64e901503af0474c85144d8e" } ]
- Response Body
- GET http://localhost:3003/api/v1/posts?page=1&limit=2
- Search a blog post by title or content
- GET http://localhost:3003/api/v1/posts/search/post title updated OR http://localhost:3003/posts/search/Content updated
- Response Body
[ { "title": "Post Title Updated", "content": "Post Content Updated", "author": "Postianus Contentus Updated", "createdAt": "2023-08-25T18:56:08.321Z", "id": "64e8f9487b164140e9d6a82b" } ]
- Response Body
- GET http://localhost:3003/api/v1/posts/search/post title updated OR http://localhost:3003/posts/search/Content updated
- Delete a blog post
- DELETE http://localhost:3003/api/v1/posts/64e8f9487b164140e9d6a82b
- HEADERS: Authorization: Bearer {access_token}
- Response Body
{ "title": "Post Title Updated", "content": "Post Content Updated", "author": "Postianus Contentus Updated", "createdAt": "2023-08-25T18:56:08.321Z", "id": "64e8f9487b164140e9d6a82b" }
- JSON Web Tokens
- Jsonwebtoken
- Mongoose
- Mongoose Paginate V2
- Express
- Jest
- Mongoose Paginate V2
- Docker and MongoDB
- Express web framework for Node.js
- Pagination: Could use mongoose-paginate-v2 library
- Tests: could be added more tests with nodejs testcontainers
- Caching: Increase the performance find all, add token storage