Backend project for managing a blog with a simple CRUD (Create, Read, Update, Delete). In this project it was possible to put into practice lessons learned with the MSC architecture (Model, Service and Controller), Node JS for code execution, Express JS for the creation of the API that communicates with the database, JSON Web Token to generate acess token, MySQL to store the data in the database, and Sequelize ORM to make transactions, migrations, seeds and querying.
JavaScript, Node JS, MySQL, Express JS, JSON Web Token (JWT), MSC Architecture, Sequelize ORM
User
- Create new user
Method: POST Endpoint: /user
Body example: { "displayName": "username example", "email": "example@email.com", "password": "pass_example", "image": "https://picsum.photos/1920/1080" }
- Login user
Method: POST Endpoint: /login
Body example: { "email": "example@email.com", "password": "pass_example", }
- Get all users
Method: GET Endpoint: /user Header - authorization: place_user_token (token generated in POST /login or POST /user)
- Get user by ID
Method: GET Endpoint: /user/:id Header - authorization: place_user_token (token generated in POST /login or POST /user)
- Delete user
Method: DELETE Endpoint: /user/me Header - authorization: place_user_token (token generated in POST /login or POST /user)
Categories
- Get all categories
Method: GET Endpoint: /categories Header - authorization: place_user_token (token generated in POST /login or POST /user)
- Create category
Method: POST Endpoint: /categories Header - authorization: place_user_token (token generated in POST /login or POST /user)
Body example: { "name": "category_name", }
Post
- Get all posts
Method: GET Endpoint: /post Header - authorization: place_user_token (token generated in POST /login or POST /user)
- Get post by ID
Method: GET Endpoint: /post/:id Header - authorization: place_user_token (token generated in POST /login or POST /user)
- Search post by query
Method: GET Endpoint: /post/search?q={search_query} Header - authorization: place_user_token (token generated in POST /login or POST /user)
- Create post
Method: POST Endpoint: /post Header - authorization: place_user_token (token generated in POST /login or POST /user)
Body example: { "title": "new title example", "content": "new content example", "categoryIds": [1, 2] }
- Update post
Method: PUT Endpoint: /post/:id Header - authorization: place_user_token (token generated in POST /login or POST /user)
Body example: { "title": "updated title example", "content": "updated content example" }
- Delete post
Method: DELETE Endpoint: /post/:id Header - authorization: place_user_token (token generated in POST /login or POST /user)
1 - Clone the project
2 - Enter the directoryblogs-api/
3 - Start docker
4 - Run the commanddocker compose up -d
5 - Run the commanddocker exec -it blogs_api bash
6 - Run the commandnpm install
inside docker to install
7 - Run the commandnpm run prestart
inside docker to create database and migrate
8 - Run the commandnpm run seed
inside docker to populate database
9 - Run the commandnpm run debug
inside docker to run application
(Optional) If you need to drop the DB, run the commandnpm run drop
inside docker