A Node.js & Typescript based API, developed with fastify, using JWT token authantication. Uses SQLite as a local database.
MIT License
✨ A Node.js & Typescript based API, developed with fastify and uses JWT Token. Uses SQLite as database. ✨
To get started with OpenCRUD API, follow these simple steps:
First of all, clone the repository and install de dependencies.
pnpm install
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"
Now we must setup our database. We're going to apply the migrations executing the following command:
npx prisma migrate deploy
Now, you can run the API with
pnpm run dev
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
.
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 |
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'
GET - '/tasks/:taskId'
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'
Params | Type | Default | Optional |
---|---|---|---|
taskId |
string | - | false |
The technologies used to develop this application was:
OpenCRUD API is released under the MIT License.