Library Management REST API
A clean, practical, and interview-friendly Spring Boot REST application.
🔹 Core Features
You build APIs to manage:
Books
Users (Students/Admin)
Book Issue / Return
Fine calculation
🧩 Entities (Simple & Realistic)
1️⃣ Book
id
title
author
isbn
availableCopies
2️⃣ User
id
name
email
role (STUDENT / ADMIN)
3️⃣ IssueRecord
id
issueDate
dueDate
returnDate
status (ISSUED / RETURNED)
🌐 REST Endpoints (Using ResponseEntity)
📘 Book APIs
POST /api/books
GET /api/books
GET /api/books/{id}
PUT /api/books/{id}
DELETE /api/books/{id}
Example:
@PostMapping
public ResponseEntity<Book> addBook(@RequestBody Book book) {
Book savedBook = [Link](book);
return new ResponseEntity<>(savedBook, [Link]);
}
👤 User APIs
POST /api/users
GET /api/users
GET /api/users/{id}
🔄 Issue / Return APIs
POST /api/issue/{bookId}/{userId}
PUT /api/return/{issueId}
import [Link];
public class Car {
private int speed;
private String unit;
Car(int speed, String unit) {
[Link] = speed;
[Link] = unit;
}
public int getSpeed() {
return speed;
}
public String getUnit() {
return unit;
}
public void setSpeed(int speed) {
[Link] = speed;
}
public void setUnit(String unit) {
[Link] = unit;
}
@Override
public String toString() {
return "Car with the maximum speed of " + speed + " " + unit;
}
}
public class Boat {
private int speed;
Boat(int speed) {
[Link] = speed;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
[Link] = speed;
}
@Override
public String toString() {
return "Boat with the maximum speed of " + speed + " knots";
}
}
public class CarTest {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
nt q = [Link]([Link]());
for (int i = 0; i < q; i++) {
String[] input = [Link]().split(" ");
if (input[0].equals("car")) {
int speed = [Link](input[1]);
String unit = input[2];
Car car = new Car(speed, unit);
[Link](car);
} else if (input[0].equals("boat")) {
int speed = [Link](input[1]);
Boat boat = new Boat(speed);
[Link](boat);
}
}
}
}
Library Management REST API in Java (Spring Boot). This is a very common use case and fits
perfectly with your Spring Boot + REST background 👍
🔹 Features
Add / view / update / delete books
Issue a book to a member
Return a book
RESTful APIs with proper HTTP status codes
🔹 Tech Stack
Java 17+
Spring Boot
Spring Data JPA
H2 / MySQL
REST APIs (JSON)
🔹 Project Structure
[Link]
│
├── controller
│ └── [Link]
│
├── entity
│ └── [Link]
│
├── repository
│ └── [Link]
│
├── service
│ └── [Link]
│
└── [Link]
🔹 Book Entity
@Entity
public class Book {
@Id
@GeneratedValue(strategy = [Link])
private Long id;
private String title;
private String author;
private boolean available = true;
// getters & setters
}
🔹 Repository
public interface BookRepository extends JpaRepository<Book, Long> {
}
🔹 Service Layer
@Service
public class BookService {
@Autowired
private BookRepository bookRepository;
public Book addBook(Book book) {
return [Link](book);
}
public List<Book> getAllBooks() {
return [Link]();
}
public Book issueBook(Long id) {
Book book = [Link](id)
.orElseThrow(() -> new RuntimeException("Book not found"));
if (![Link]()) {
throw new RuntimeException("Book already issued");
}
[Link](false);
return [Link](book);
}
public Book returnBook(Long id) {
Book book = [Link](id)
.orElseThrow(() -> new RuntimeException("Book not found"));
[Link](true);
return [Link](book);
}
}
🔹 Controller (REST API)
@RestController
@RequestMapping("/api/books")
public class BookController {
@Autowired
private BookService bookService;
@PostMapping
public ResponseEntity<Book> addBook(@RequestBody Book book) {
return new ResponseEntity<>([Link](book), [Link]);
}
@GetMapping
public ResponseEntity<List<Book>> getAllBooks() {
return [Link]([Link]());
}
@PutMapping("/issue/{id}")
public ResponseEntity<Book> issueBook(@PathVariable Long id) {
return [Link]([Link](id));
}
@PutMapping("/return/{id}")
public ResponseEntity<Book> returnBook(@PathVariable Long id) {
return [Link]([Link](id));
}
}
🔹 Sample API Endpoints
Method Endpoint Description
POST /api/books Add book
GET /api/books View all books
PUT /api/books/issue/{id} Issue book
PUT /api/books/return/{id} Return book
🔹 Sample JSON (Add Book)
{
"title": "Effective Java",
"author": "Joshua Bloch"
}
🔹 Improvements (Nice to Have)
DTO + ModelMapper
Custom Exception + Global Exception Handler
JWT Security (Admin/User)
Member Entity & Issue History
Pagination & Sorting
If you want, I can:
convert this into JWT secured API
add Member & Issue records
make it perfect for Fresco Play / interview submission
provide Swagger documentation
So Please visit this page