This project is a RESTful API for managing bookmarks using NestJS, a progressive Node.js framework for building efficient and scalable server-side applications.
- CRUD operations for bookmarks
- JWT authentication and authorization
- Validation and error handling
- Pagination and filtering
- Docker support
- Node.js (>= 14)
- bun OR npm (>= 6)
- Docker and Docker Compose (optional)
- Clone the repository
git clone https://github.com/RogerioPiatek/nestjs-bookmarks-api.git
- Install the dependencies
cd nestjs-bookmarks-api
bun install
- Copy the
.env.example
file and rename it to.env
cp .env.example .env
- Update the environment variables in the
.env
file according to your preferences
# Application port
PORT=3000
# Database connection
DATABASE_URL=""
# JWT secret
JWT_SECRET="secret"
- Run the database migrations
bunx prisma migrate dev
- Start the application
# development mode
bun start:dev
Alternatively, you can use Docker to run the application and the database with one command
docker-compose up -d
You can use any HTTP client to interact with the API, such as Postman or curl.
Here are some examples of requests and responses:
Request:
curl --location --request POST 'http://localhost:3000/auth/signup' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "test",
"password": "test123"
}'
Response:
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsInVzZXJuYW1lIjoidGVzdCIsImlhdCI6MTYyOTg0MjQwNCwiZXhwIjoxNjI5ODQ2MDA0fQ.8dU1FpHwNq2xSdPQxPZLxYw2l2xv0n3a4SNZ4lH8KfE"
}
Request:
curl --location --request POST 'http://localhost:3000/auth/signin' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "test",
"password": "test123"
}'
Response:
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsInVzZXJuYW1lIjoidGVzdCIsImlhdCI6MTYyOTg0MjQwNCwiZXhwIjoxNjI5ODQ2MDA0fQ.8dU1FpHwNq2xSdPQxPZLxYw2l2xv0n3a4SNZ4lH8KfE"
}
Request:
curl --location --request POST 'http://localhost:3000/bookmarks' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <access_token>' \
--data-raw '{
"title": "NestJS",
"link": "https://nestjs.com/"
}'
Response:
{
"id": 1,
"createdAt": "2024-01-20T06:24:53.455Z",
"updatedAt": "2024-01-20T06:24:53.455Z",
"title": "NestJS",
"description": null,
"link": "https://nestjs.com/",
"userId": 1
}
Request:
curl --location --request GET 'http://localhost:3000/bookmarks/1' \
--header 'Authorization: Bearer <access_token>'
Response:
{
"id": 1,
"createdAt": "2024-01-20T06:26:53.455Z",
"updatedAt": "2024-01-20T06:26:37.583Z",
"title": "NestJS",
"description": null,
"link": "https://nestjs.com/",
"userId": 1
}
Contributions, issues, and feature requests are welcome. Feel free to check the issues page if you want to contribute.
This project is licensed under the MIT License. Nest is MIT Licensed.