/Book-API-SpringBoot

Creating a REST API of Books connected with Postgres DB with MVC Architecture having Data, Service, and API Layer

Primary LanguageJava

A Simple Book REST API Application using Springboot utilising Java-Maven

Methods to Run the Code

1. To run the application:

  1. Install the .jar file from packages on gitub

  2. After Installing usejava command run the generated SNAPSHOT.jar file - java -jar NAME_OF_FILE.jar

2. To run the code(Using Maven):

  1. Install the dependencies needed to run the application and also downloading SNAPSHOT of production application - mvn install

  2. After Installing using java command run the generated SNAPSHOT.jar file - java -jar .\target\demo-0.0.1-SNAPSHOT.jar

3. To run the local springboot application:

  1. Directly run the DemoApplication.java to locally run the code and to publish changes as well

Endpoints created:

  • GET /api/v1/books - Gets all Books from DB
  • GET /api/v1/books/{bookId} - Gets Book with specified ID from DB
  • POST /api/v1/books - Adds a new book in DB if it does not exists
  • DELETE /api/v1/books/{bookId} - Deletes a book in DB if it exists
  • PUT /api/v1/books/{bookId}?bookName=...&author=...&publication=...&dop=... - Updates a book in DB if it exists, not all parameters required

Steps for Springboot:

  1. After extracting from Spring Initializr, comment JPA until repository is not implemented
  2. Use @RestController and @RequestMapping for defining path in Controller File.
  3. Use @Service to set Service file as Service Func.
  4. Use @Autowired in both Controller and Service for Dependency Injection
  5. For Table in DB, use @Table and @Entity and use necessary generators for different variables.
  6. Use @Repository in repository file
  7. in Config file, use @Configuration on class and @Bean for method to add initial values in DB when running command
  8. If we use spring.jpa.hibernate.ddl-auto=create-drop, then there is need for Config, else use, ...=update, to dont delete the DB Details when application reloads

To Upload Package on GitHub:

  1. Change the REPOSITORY on /{user}/.m2/settings.xml and add OWNER and GITHUB_TOKEN
  2. Add Distrbution Management in pom.xml