A comprehensive RESTful API for managing a library system with user authentication, book catalog management, author management, and book borrowing functionality.
This Library Management API provides a complete backend solution for a digital library system. It allows users to browse books, check author information, borrow books, and return them. Administrators have additional capabilities to manage the entire library catalog, user accounts, and monitor borrowing activities.
- User Authentication: Secure JWT-based authentication system
- Role-Based Access Control: Different permissions for regular users and administrators
- Book Catalog: Comprehensive book management with metadata
- Author Management: Track author information and their publications
- Borrowing System: Borrow and return functionality with status tracking
- Admin Dashboard: Special endpoints for administrative functions
| Method | Endpoint | Description |
|---|---|---|
| POST | /auth/register |
Register a new user |
| POST | /auth/login |
User login with email and password |
| Method | Endpoint | Description |
|---|---|---|
| GET | /auth/user |
Get current user information |
| GET | /auth/user/:id |
Get user by ID |
| PATCH | /auth/user/:id |
Update user information |
| Method | Endpoint | Description |
|---|---|---|
| GET | /authors/ |
Get all authors |
| GET | /authors/:id |
Get author by ID |
| Method | Endpoint | Description |
|---|---|---|
| GET | /books/ |
Get all books |
| GET | /books/:id |
Get book by ID |
| Method | Endpoint | Description |
|---|---|---|
| POST | /borrowings/ |
Borrow a book |
| GET | /borrowings/my |
Get books borrowed by the current user |
| PUT | /borrowings/:bookId/return |
Return a borrowed book |
User Management
| Method | Endpoint | Description |
|---|---|---|
| GET | /admin/users |
Get all users |
| GET | /admin/user/:id |
Get user by ID |
| PATCH | /admin/user/:id |
Update user information |
| DELETE | /admin/user/:id |
Delete user |
Author Management
| Method | Endpoint | Description |
|---|---|---|
| POST | /admin/author |
Add a new author |
| PATCH | /admin/author/:id |
Update author information |
| DELETE | /admin/author/:id |
Delete author |
Book Management
| Method | Endpoint | Description |
|---|---|---|
| POST | /admin/book |
Add a new book |
| GET | /admin/book |
Get all books |
| GET | /admin/book/:id |
Get book by ID |
| PATCH | /admin/book/:id |
Update book information |
| DELETE | /admin/book/:id |
Delete book |
Borrowing Management
| Method | Endpoint | Description |
|---|---|---|
| GET | /admin/borrowings |
Get all borrowed books |
| PUT | /admin/borrowings/:bookId/return |
Force return a borrowed book |
Contact Management
| Method | Endpoint | Description |
|---|---|---|
| GET | /admin/contact |
Get all contact requests |
| DELETE | /admin/contact/:id |
Delete a contact request |
The API uses JWT (JSON Web Token) for authentication. After successful login or registration, a token is returned which must be included in the Authorization header for protected routes:
Authorization: Bearer <your_token_here>
- Clone the repository
- Install dependencies:
npm install - Set up environment variables (see below)
- Start the server:
npm start
Create a .env file in the root directory with the following variables:
PORT=3000
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key
Note: For Postman testing, update the environment variables for:
auth: Your authentication service base URLauthors: Your authors service base URLbooks: Your books service base URLborrowings: Your borrowings service base URLadmin: Your admin service base URL