Skip to content

Spring Boot RESTful API that allows users to manage a collection of books. Users can perform various CRUD (Create, Read, Update, Delete) operations on books using this API.

License

ajaynegi45/Library-API

Repository files navigation

Library-API Project 📚

This project is a simple Spring Boot application that provides a RESTful API for managing books. It allows users to perform CRUD (Create, Read, Update, Delete) operations on books using the API. It adding new books, updating existing ones, searching for books, and deleting books.

Project Structure 📂

The project consists of several components, each serving a specific purpose:

  1. Controller: Defines the RESTful endpoints for handling book-related requests. It interacts with the Service to perform various operations.

  2. Service: Contains the business logic for book-related operations. It interacts with the DAO to access the database.

  3. DAO: Provides access to the database using Spring Data JPA. It extends the JpaRepository interface to enable CRUD operations.

  4. Entities: Represents the entity (model) for a book. It is annotated with @Entity to indicate it's a JPA entity and corresponds to a database table.


API Endpoints 🔗

API Collection Documentation on Postman for testing API

Add Book 📗

Add a new book to the database.

  • URL: POST /addBook
  • Request Body:
    {
      "bookName": "Book Title",
      "authorName": "Author Name",
      "bookPrice": 29.99,
      "stockQuantity": 50
    }
  • Response:
    • 201 Created: Book added successfully
    • 409 CONFLICT: if there is a conflict (e.g., book not able to store ).
    • 500 INTERNAL_SERVER_ERROR: if there is an internal server error.

Update Book 📘

Update an existing book's details by providing the book ID.

  • URL: PUT /updatebook/{bookid}
  • Request Body:
    {
      "bookName": "Updated Book Name",
      "authorName": "Updated Author Name",
      "bookPrice": "Updated Book Price",
      "stockQuantity": "Updated Stock Quantity"
    }
  • Response:
    • 202 Accepted: Book updated successfully
    • 404 Not Found: Book with the given ID not found


GET Book 📔

Endpoint Method URL Request Parameter Response
Get All Books GET /getAllBooks None List of BookEntity objects
Get Book by ID GET /getBookById/{id} id (Path parameter) BookEntity object
Get Books by Name Starting With GET /bookNameStartWith/{bookName} bookName (Path parameter) List of BookEntity objects
Get Books by Name Ending With GET /bookNameEndWith/{bookName} bookName (Path parameter) List of BookEntity objects
Get Books by Name Containing GET /bookNameContain/{bookName} bookName (Path parameter) List of BookEntity objects


DELETE Book 📕

Endpoint Method URL Request Parameter Response
Delete Book by ID DELETE /deleteBookById/{id} id (Path parameter) 202 Accepted : Book deleted successfully

OR

404 Not Found : Book with the given ID not found
Delete Book by Name DELETE /deleteBookByName/{bookName} bookName (Path parameter) 202 Accepted : Books deleted successfully

OR

404 Not Found : No books found with the given name
Delete Books by Author DELETE /deleteAllByAuthor/{authorName} authorName (Path parameter) 202 Accepted : Books deleted successfully

OR

404 Not Found : No books found with the given author name

How to Run the Project 💨

  1. Ensure you have Java and MySQL installed on your system.
  2. Clone or download the project from the repository.
  3. Import the project into your preferred IDE (e.g., Eclipse, IntelliJ).
  4. Set up the MySQL database and update the database configurations in the application.properties file (not provided in the code).
  5. Build and run the project using the IDE or by running mvn spring-boot:run command from the project root directory.

Technologies Used 🌐



‼️ Important Note ‼️

  • You need to set up the database and make sure the application properties are correctly configured to run the project successfully.

Upcoming Update

Adding more features, error handling, authentication, and security measures.

Contributing 🤗

Feel free to explore and use these project. If you encounter any issues or have suggestions for improvements, please feel free to contribute or reach out for assistance.

Contributions are always welcome! ✨

See contributing.md for ways to get started.

Please adhere to this project's code_of_conduct.md.

Contact Information 📧

If you have any questions or would like to connect, please don't hesitate to reach out. I'd be more than happy to chat and learn from your experiences too.

Email: contact me

Thankyou ❤️

Thank you for taking the time to explore my project. I hope you find them informative and useful in your journey to learn Java and enhance your programming skills. Your support and contributions are highly appreciated. Happy coding! ✨

Authors

Contributors

About

Spring Boot RESTful API that allows users to manage a collection of books. Users can perform various CRUD (Create, Read, Update, Delete) operations on books using this API.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks