The Blogs API project is a Restful API which allows an user to interact with all basic CRUD operations in a blog, including creating and authenticating users, as well as reading, posting and updating posts.
- NodeJS and Express for creating endpoints with request and response functions;
- Sequelize for interacting with the database; and
- JWT for creating tokens on login and authenticating the tokens on the relevant endpoints.
Dokerfiles, Docker Compose and Sequelize config files were provided by Trybe and were not written by me.
- Clone the repository
git clone [email protected]:P-dPF/blogs-api.git
- Navigate into the directory created in the previous step
cd blogs-api
- Build the docker images
docker-compose up -d --build
- Access the interactive terminal within the node container initialized in the previous step
docker exec -it blogs_api bash
- Install depedencies (in the interctive terminal)
npm install
- Populate the database (in the interctive terminal)
npm run prestart && npm run seed
(expected node v. 16 or higher and mysql installed locally)
- Clone the repository
git clone [email protected]:P-dPF/blogs-api.git
- Navigate into the directory created in the previous step
cd blogs-api
- Install depedencies
npm install
- Change the .env.example file name to .env and set the relevant environment variables for your machine.
- Populate the database
npm run prestart && npm run seed
📬 If you have any insights or feedbacks that you would like to share or if need further info on how to run the application, please don't hesitate to contact me :) My contact info is in my profile main page.
💡 Use Thunder Client, Insomnia, Postman or a web browser to make requests to the API. The relevant web protocol and endpoints are indicated below.
- POST
http://localhost:3000/login
to login. Use a standard user created in the seeding. Example request body.
{
"email": "[email protected]",
"password": "123456"
}
Copy the token generated in the endpoint above and insert it in the Authorization header for the requests marked with "!"
- POST
http://localhost:3000/user
to create a user. Example request body
{
"displayName": "Brett Wiltshire",
"email": "[email protected]",
"password": "123456",
"image": "http://4.bp.blogspot.com/_YA50adQ-7vQ/S1gfR_6ufpI/AAAAAAAAAAk/1ErJGgRWZDg/S45/brett.png"
// image is not mandatory
}
- ☝️ GET
http://localhost:3000/user
to list all users - ☝️ GET
http://localhost:3000/user/:id
to list a specific user (replace the ":id" in the URL with a number) - ☝️ POST
http://localhost:3000/categories
to create a new subject category for the posts. Example request body:
{
"name": "Typescript"
}
- ☝️ GET
http://localhost:3000/categories
to list all categories - ☝️ POST
http://localhost:3000/post
to create a new post. Example request body:
{
"title": "Latest updates, August 1st",
"content": "The whole text for the blog post goes here in this key",
"categoryIds": [1, 2]
}
- ☝️ GET
http://localhost:3000/post
to list all posts. - ☝️ GET
http://localhost:3000/post/:id
to list a specific post (replace the ":id" in the URL with a number). - ☝️ PUT
http://localhost:3000/post/:id
to update a specific post (replace the ":id" in the URL with a number). Example request body:
{
"title": "Latest updates, August 1st",
"content": "The whole text for the blog post goes here in this key"
}
- ☝️ DELETE
http://localhost:3000/post/:id
to delete a specific post (replace the ":id" in the URL with a number). - ☝️ DELETE
http://localhost:3000/user/me
to delete the logged user (replace the ":id" in the URL with a number). - ☝️ GET
http://localhost:3000//post/search?q=searchTerm
to delete the logged user (replace the "searchTerm" in the URL with a word to search). Example: vamos