RESTack is an experimental REST API developed exclusively for educational purposes.
Currently, there are some different operations that can be performed, such as a CRUD for users and projects through a Many-To-Many association. Furthermore, there are some rules for route access, e.g. only authenticated users can create, update and delete projects/users, but retrieving them is allowed for everyone.
- Node.js
- Express
- PostgreSQL
- Sequelize
- JWT
- Bcrypt
- Body Parser
- Cookie Parser
- ESLint
- Prettier
- Insomnia
- DBeaver
HTTP response status codes (MDN Web Docs)
First of all, configure the .env
file with the information related to secrets and database configuration:
JWT_SECRET=#
PG_PASSWORD=#
PROJECT_NAME=restack
ADMIN=#
HOST=localhost
DIALECT=postgres
Then, run the following command to install the dependencies from package.json:
yarn install
Run the migration from Sequelize:
sequelize db:migrate
Finally, start the project with:
yarn start
POST @ http://localhost:3000/signup
Used to create a new user with name
, email
and password
. Returns the user's info or an error message (e.g. email
already exists).
POST @ http://localhost:3000/login
Used to authenticate the user using email
and password
. Generates a cookie with the user credentials (JSON Web Token), necessary to manage the projects. If there is some wrong information a message is sent back.
GET @ http://localhost:3000/user
Used to retrieve all the users from the database.
GET @ http://localhost:3000/project
Used to retrieve all the projects from the database.
GET @ http://localhost:3000/user/id
Used to retrieve a user by its id
, or a message if it not exists.
GET @ http://localhost:3000/project/id
Used to retrieve a project by its id
, or message if it not exists.
POST @ http://localhost:3000/project/id/add_user
Used to add a user to a project through the project's id
.
POST @ http://localhost:3000/user/id/add_project
Used to add a project to a user through the user's id
.
Some other routes available are:
-
POST @ http://localhost:3000/project: Create new project with
name
,stack
-
PUT @ http://localhost:3000/project/id: Update existing project by
id
-
PUT @ http://localhost:3000/user/id: Update existing user by
id
-
DELETE @ http://localhost:3000/project/id: Delete project by
id
-
DELETE @ http://localhost:3000/user/id: Delete user by
id
An important aspect of RESTack is the user authentication, necessary to perform some actions, such as create a project: