Skip to content

RogerioPiatek/nestjs-bookmarks-api

Repository files navigation

Nest Logo

NestJS Bookmarks API 📚

This project is a RESTful API for managing bookmarks using NestJS, a progressive Node.js framework for building efficient and scalable server-side applications.

Features ✨

  • CRUD operations for bookmarks
  • JWT authentication and authorization
  • Validation and error handling
  • Pagination and filtering
  • Docker support

Tech Stack 🛠️

Getting Started 🚀

Prerequisites

Installation

  1. Clone the repository
git clone https://github.com/RogerioPiatek/nestjs-bookmarks-api.git
  1. Install the dependencies
cd nestjs-bookmarks-api
bun install
  1. Copy the .env.example file and rename it to .env
cp .env.example .env
  1. 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"
  1. Run the database migrations
bunx prisma migrate dev
  1. 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

Usage 📝

You can use any HTTP client to interact with the API, such as Postman or curl.

Here are some examples of requests and responses:

Create a user and get a JWT token

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"
}

Login and get a JWT token

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"
}

Create a bookmark

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
}

Get bookmark by id

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
}

And other CRUD operations!

Contributing 🤝

Contributions, issues, and feature requests are welcome. Feel free to check the issues page if you want to contribute.

License 📄

This project is licensed under the MIT License. Nest is MIT Licensed.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors