/restack-api

🔄 Experimental REST API.

Primary LanguageJavaScriptMIT LicenseMIT

⬆️ RESTack API ⬇️

RESTack API

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.


🧰 Tools & Dependencies

  • Node.js
  • Express
  • PostgreSQL
  • Sequelize
  • JWT
  • Bcrypt
  • Body Parser
  • Cookie Parser
  • ESLint
  • Prettier
  • Insomnia
  • DBeaver

♾️ Helpful Content

HTTP response status codes (MDN Web Docs)


✅ Installation & Execution

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


▶️ Examples

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_201

POST_400


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.

POST_200

POST_404


GET @ http://localhost:3000/user

Used to retrieve all the users from the database.

GET_200


GET @ http://localhost:3000/project

Used to retrieve all the projects from the database.

GET_200


GET @ http://localhost:3000/user/id

Used to retrieve a user by its id, or a message if it not exists.

GET_200


GET @ http://localhost:3000/project/id

Used to retrieve a project by its id, or message if it not exists.

GET_200


POST @ http://localhost:3000/project/id/add_user

Used to add a user to a project through the project's id.

POST_200


POST @ http://localhost:3000/user/id/add_project

Used to add a project to a user through the user's id.

POST_200


Some other routes available are:


An important aspect of RESTack is the user authentication, necessary to perform some actions, such as create a project:

POST_401