crud-tasks

A Node.js & Typescript based API, developed with fastify, using JWT token authantication. Uses SQLite as a local database.

MIT License

Stars
0
Committers
1

OpenCRUD API

✨ A Node.js & Typescript based API, developed with fastify and uses JWT Token. Uses SQLite as database. ✨

Table of contents

Getting Started

To get started with OpenCRUD API, follow these simple steps:

1. Installation

First of all, clone the repository and install de dependencies.

pnpm install

2. Setting up your environment

Now we must setup our environment variables. Create a file on root as .env. Inside, put all data like is here in: .env.example

NODE_ENV=dev

# Auth
JWT_SECRET=YOUR_SECRET_HERE

# Database
DATABASE_URL="path_from_your_database"

3. Setting up database

Now we must setup our database. We're going to apply the migrations executing the following command:

npx prisma migrate deploy

4. Run

Now, you can run the API with

pnpm run dev

🛠️ Features

FRs (Functional requirements)

  • It must be possible to register;
  • It must be possible to authenticate;
  • It must be possible to obtain the profile of a user;
  • It must be possible to edit a user;
  • It must be possible to delete a user;
  • It must be possible to create a new task;
  • It must be possible to edit a task;
  • It must be possible to list all tasks from a user;
  • It must be possible to delete a task

BRs (Business Rules)

  • The user must not be able to register with a duplicate e-mail address;
  • All routes besides the user register and user log-in need to be logged-in;

NFRs (Non-functional requirements)

  • The user's password must be encrypted;
  • The application data must be persisted in a SQLite database;
  • The user must be identified by a JWT (JSON Web Token);

🛑 Endpoints

Here you can see all the endpoints of the application. You'll need to use the prefix "/api", so to example: If you want to register a user, use: [protocol]://[url]/api/users.

Users

  • POST - '/users'
    • This is the user's entry route, where the user will register with in the application. You must send the request with a data equal a some user's informations on the body of the requisition. "name" is optional.

      Params Type Default Optional
      name string - true
      email string - false
      password string - false
  • POST - '/users/login'
    • This is the authenticate route. Here, the user can log-in on our application. Send the data as the body of the request as a JSON. After that, we will generate a access token that contains the userId and his email.

      Params Type Default Optional
      email string - false
      password string - false
  • GET - '/users'
    • This is the route to get all data about the user logged-in. Need to pass the JWT Token as Authorization Bearer to identify himself.

      Header Type
      Authorization Bearer
  • PUT - '/users/edit'
    • This is the route dedicated to edit user's profile. First, the user need to pass his JWT Token as Authorization Bearer to identify himself. Also need to send the data as the body of the request as a JSON.

      Header Type
      Authorization Bearer

      Params Type Default Optional
      name string - true
      email string - true
      password string - true
  • DELETE - '/users/delete'
    • This is the delete route for users. Here, the user can delete his own account, just passing the JWT Token as Authorization Bearer to identify himself.

      Header Type
      Authorization Bearer

Tasks

On Tasks, every route needs to be authenticated, that means every request must have the following header with the JWT Token: Authorization Bearer ${token}.

  • POST - '/tasks'
    • This route is dedicated to create a new task. The data of the task shall be passed on the requisition's body. The new task is going to be assigned to the logged-in user.

      Params Type Default Optional
      title string - false
      description string - true
  • GET - '/tasks/user'
    • This route is going to return all tasks that belong to the user logged-in.
  • GET - '/tasks/:taskId'
    • This route is going to return all data of a specific task. Need to pass the task's ID as a param on url.
      Params Type Default Optional
      taskId string - false
  • PUT - '/tasks/:taskId'
    • This is the route dedicated to edit a specific task. First, the user need to provide de taskId on the url. Also need to send the data that want to change as the body of the request as a JSON.

      Params Type Default Optional
      title string - true
      description string - true
      isFinished boolean false true
  • DELETE - '/tasks/:taskId'
    • This route is going to delete a specific task. Need to pass the task's ID as a param on url. A user can only delete a task that is assigned to him.
      Params Type Default Optional
      taskId string - false

🚀 Technologies

The technologies used to develop this application was:

📝 License

OpenCRUD API is released under the MIT License.

✍ Author