This Node.js application provides an API for managing books and categories, offering full CRUD functionality.
- Easily manage books and categories with intuitive CRUD operations.
- Effortlessly filter books by various parameters such as title, publication year, and number of pages.
-
Clone Repository:
git clone https://github.com/diazlp/bookaholic-api-expressjs cd bookaholic-api-expressjs
-
Install Dependencies:
npm install
-
Database Configuration:
Navigate to
config/config.js
and configure your database settings:"username": "postgres", "password": "postgres", "database": "bookaholic-dev", "host": "127.0.0.1", "dialect": "postgres"
-
Run Migration & Seeder:
Execute the following commands to run migrations and seeders:
npx sequelize-cli db:migrate && npx sequelize-cli db:seed:all
Default credentials:
username: admin password: admin
-
Run the Server:
npm run dev
-
Accessing the server:
Explore the API documentation at
http://localhost:8000/docs
.Access the API at
http://localhost:8000
.
POST /auth/register
: Register a new user.POST /auth/login
: Log in with existing credentials.
GET /categories
: Retrieve all categories.POST /categories
: Create a new category.PATCH /categories/:id
: Update an existing category by ID.DELETE /categories/:id
: Delete a category by ID.GET /categories/:id/books
: Retrieve all books within a specific category.
GET /books
: Retrieve all books.POST /books
: Create a new book.PATCH /books/:id
: Update an existing book by ID.DELETE /books/:id
: Delete a book by ID.
- Use query parameters to filter books and/or categories:
title
: Search by book title (case-insensitive).minYear
: Minimum publication year.maxYear
: Maximum publication year.minPage
: Minimum number of pages.maxPage
: Maximum number of pages.sortByTitle
: Sort books by title in ascending (asc
) or descending (desc
) order.
Example:
localhost:8000/books?sortByTitle=asc&minYear=2000&maxPage=150
localhost:8000/books?title=algoritma&minYear=2000&maxYear=2010
localhost:8000/categories/1/books?sortByTitle=desc&minYear=2000&maxPage=150
- Express.js
- Bcrypt for Password Hashing
- JWT for Authentication
- Sequelize ORM for PostgreSQL Database
- Swagger for API Documentation