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.gitGo to the project directory
cd blog-apiInstall dependencies
npm iStart the server
docker-compose up -dMigrate and seed the database
npm run prestart
npm run seedAccess the server terminal
docker exec -it blogs_api bashStart the service inside the container terminal
npm run devThe 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 /loginRequisition body:
{
"email": ${userEmail},
"password": ${userPassword},
}| Parameter | Type | Description |
|---|---|---|
userEmail |
string |
Required. Login email |
userPassword |
string |
Required. Login password |
POST /userRequisition 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 /categoriesRequisition body:
{ "name": ${catName} }| Parameter | Type | Description |
|---|---|---|
catName |
string |
Required. Category name |
GET /categories POST /postRequisition 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 testNode.js, Express.js, MySQL, Sequelize, JWT, Docker, REST API, CRUD, MSC, Jest