First of all, I would like to inform you that this project is intended to be a relatively simple project. For this reason, in some cases, proper treatment was not carried out. Nonetheless, I hope you still enjoy it. 😺
- Lucas Winicius
git clone https://github.com/Lucas-Winicius/jokes_api.git
cd jokes_api
Install dependencies:
npm install
Now that everything is installed, let's configure the environment variables.
Create a file called .env at the root of the project, following the parameters of the .env.example file.
PORT=3000
DATABASE_URL=
JWT_SECRET=
COOKIE_SIGNATURE=
COOKIE_NAME=
To do this, it's very simple. Just execute the commands below. The first one will create the database migrations, and the second one will start your project on the port defined in the .env file.
npm run build
npm run start
For development, I recommend the command below:
npm run start:dev
With all the steps complete, we now need to understand a little about all the routes. Or, if you prefer to understand on your own, just read the files inside /src/router.js.
This route does not require prior login and will return all the posts with their respective authors. Remember to declare the page; otherwise, it will always be set to 1.
Parameters on body:
none
This route will create a new user with the unique 'name' field and will send a login cookie that will be used in the next routes.
Parameters on body:
name
password
This route will use the login cookie to return all the information of the logged-in user, such as their name and all associated posts.
Parameters on body:
none
Also, using the login cookie, this route will modify the user's data, such as password or name. After using this route, it will be necessary to log in again.
Parameters on body:
name
password
Using the login cookie, this route will delete the logged-in user.
Parameters on body:
none
This route will return a login cookie to you.
Parameters on body:
name
password
This route will delete your login cookie.
Parameters on body:
none
This route will create a new post and associate it with you.
Parameters on body:
title
joke
This route will return the post specified by the id.
Parameters on body:
none
Using the login cookie, this route will edit the post, remembering that this post must belong to you.
Parameters on body:
title
joke
Using the login and post id, this route will delete the post.
Parameters on body:
none
It is important to note that the routes with the 'DELETE' method will not actually delete they will only update the value of the 'deleted' column to true.
This project could have been much more complex, but since I just wanted to create a simple and quick project, I ended up leaving it this way. Nonetheless, regardless of everything, I hope you all enjoy it. ❤️
Thank you for reading up to this point.