A blog backend service with CRUD endpoints and database integration that runs locally on a Docker container. It can authenticate users and manage their blog posts on a database.
- GET, POST, PUT and DELETE endpoints
- Database integration
- MSC architecture
- Unit tests
Clone the project
git clone https://github.com/Virkkunen/blog-api.git
Go to the project directory
cd blog-api
Install dependencies
npm i
Start the server
docker-compose up -d
Migrate and seed the database
npm run prestart
npm run seed
Access the server terminal
docker exec -it blogs_api bash
Start the service inside the container terminal
npm run dev
The service is now running on localhost:3001
Endpoint will return a token used to login. User needs to add this token as an Authentication
header on future requisitions.
POST /login
Requisition body:
{
"email": ${userEmail},
"password": ${userPassword},
}
Parameter | Type | Description |
---|---|---|
userEmail |
string |
Required. Login email |
userPassword |
string |
Required. Login password |
POST /user
Requisition body:
{
"displayName": ${userName},
"email": ${userEmail},
"password": ${userPassword},
"image": ${userImage}
}
Parameter | Type | Description |
---|---|---|
userName |
string |
Required. User display name |
userEmail |
string |
Required. Email used for login |
userPassword |
string |
Required. Password used for login |
userImage |
string |
Profile picture URL |
GET /user
GET /user/${userId}
Parameter | Type | Description |
---|---|---|
userId |
number |
Required. User ID |
DELETE /user/me
POST /categories
Requisition body:
{ "name": ${catName} }
Parameter | Type | Description |
---|---|---|
catName |
string |
Required. Category name |
GET /categories
POST /post
Requisition body:
{
"title": ${postTitle},
"content": ${postContent},
"categoryIds": ${catIds}
}
Parameter | Type | Description |
---|---|---|
postTitle |
string |
Required. Post title |
postContent |
string |
Required. Post content |
catIds |
number array |
Required. IDs of the categories post belongs to, eg.: [1, 2] |
GET /post
GET /post/${postId}
Parameter | Type | Description |
---|---|---|
postId |
number |
Required. ID of the post |
PUT /post/${postId}
Requisition body:
{
"title": ${postTitle},
"content": ${postContent}
}
Parameter | Type | Description |
---|---|---|
postId |
number |
Required. ID of the post |
postTitle |
string |
Required. Post title |
postContent |
string |
Required. Post content |
DELETE /post/${postId}
Parameter | Type | Description |
---|---|---|
postId |
number |
Required. ID of the post |
Will return all posts with title and/or content matching the query
GET /post/search?q=${query}
Parameter | Type | Description |
---|---|---|
query |
string |
Required. Search query |
To run tests, run the following command
npm run test
Node.js, Express.js, MySQL, Sequelize, JWT, Docker, REST API, CRUD, MSC, Jest