This is a RESTful API for a Library Management System developed using Spring Boot, Spring Data JPA, Spring Security, and PostgreSQL.
- Create, read, update, and delete books, patrons and borrows.
- User authentication using Basic Authentication.
- Secure password storage using Bcrypt.
- Persistent storage of blog data in a PostgreSQL database.
Make sure you have the following installed on your machine:
- Java (version 17 or higher)
- Maven
- PostgreSQL
-
Clone the repository:
git clone https://github.com/moamenhady/library-api.git
-
Build the project using Maven:
cd library-api mvn clean install
-
Configure the database connection in
src/main/resources/application.yml
:datasource: url: jdbc:postgresql://localhost:5432/your_database username: your_username password: your_password
-
Configure other properties as needed (e.g., server port, logging).
java -jar target/library-api-1.0.0.jar
Access the API at http://localhost:8080/
A default admin user with username admin
and password admin
is created in the databse on application run.
Patrons:
- GET /api/patrons : Retrieve a list of all patrons. (Requires admin authentication)
- GET /api/patrons/{id} : Retrieve details of a specific patron by ID. (Requires admin authentication)
- POST /api/patrons : Add a new patron to the system. (Requires no authentication - any one can signup as a patron)
- PUT /api/patrons/{id} : Update an existing patron's information. (Requires admin authentication)
- DELETE /api/patrons/{id} : Remove a patron from the system. (Requires admin authentication)
Books:
- GET /api/books : Retrieve a list of all books. (Requires no authentication)
- GET /api/books/{id} : Retrieve details of a specific book by ID. (Requires no authentication)
- POST /api/books : Add a new book to the library. (Requires admin authentication)
- PUT /api/books/{id} : Update an existing book's information. (Requires admin authentication)
- DELETE /api/books/{id} : Remove a book from the library. (Requires admin authentication)
Borrowing records:
- POST /api/borrow/{bookId}/patron/{patronId}: : Borrow a book. (Requires patron authentication)
- PUT /api/return/{bookId}/patron/{patronId} : Return a borrowed book. (Requires patron authentication)
This API uses Basic Authentication. Include the Authorization header in your requests with the format Basic base64(username:password).
Example using curl:
curl -X GET -H "Authorization: Basic base64(username:password)" http://localhost:8080/api/books
This project is licensed under the MIT License.