nestjs_todo_api
API • Code
Simple NestJS API for todos. Uses PostgreSQL, JWT auth.
swagger ui
/api
setup
- install dependencies:
npm install
- create
.env
file:
DATABASE_URL="postgresql://user:password@localhost:5432/todo_db"
DIRECT_URL="your_direct_url"
JWT_SECRET="your_random_secret_key"
- start server:
npm run start:dev
endpoints
auth
login:
POST /auth/login
:body:
{
"email": "test@test.com",
"password": "123"
}
returns:
{
"access_token": "##",
"refresh_token": "##"
}
refresh access token:
POST /auth/refresh
Body:
{
"refresh_token": "your_token"
}
returns:
{
"access_token": "##",
}
register new user:
POST /auth/register
:body:
{
"username": "username",
"email": "test@test.com",
"password": "123"
}
returns: created user
todos
GET /todos
- get all todosPOST /todos
- create new todoBody:
{ "title": "Buy milk", "completed": false }
PUT /todos/:id
- update todoDELETE /todos/:id
- delete todo
users
GET /users
- get all usersPOST /todos/:id
- get a userPUT /todos/update
- update the loged userpassword
/email
/username
DELETE /todos/delete
- delete the loged user
testing
npm test