Skip to content

A simple Java REST API project demonstrating the Controller, Service and Repository layers for implementing CRUD operations in a MySQL DB, using Springboot and Spring Data JPA. (credits: https://www.youtube.com/watch?v=RfHBm5yRxuw)

Notifications You must be signed in to change notification settings

adityaSS13/RESTful-API-demonstrating-CRUD-operations-using-Springboot-and-MySQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RESTful-API-demonstrating-CRUD-operations-using-Springboot-and-MySQL

Steps:

  • Create a Spring boot project on Spring Initializr (add the dependencies: Spring web, MySQL Driver and Spring Data JPA
  • Run MySQL server process in a docker container: Start docker desktop (windows) and type this in the command prompt tool (substitute the name and password fields with your chosen ones):
    • docker run --name mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=<db_name> -e MYSQL_USER= -e MYSQL_PASSWORD= -p 3306:3306 -d mysql:8
    • docker exec -it mysql mysql -u myuser -p (to get inside the MySQL server running inside the container)
  • Optionally, connect to this DB in MySQL Workbench
  • Add the following application.yaml to the project (check repo for its path):
    spring:
    datasource:
      url: jdbc:mysql://localhost:3306/<db_name>
      username: <username>
      password: <password>
      driver-class-name: com.mysql.cj.jdbc.Driver
    
    jpa:
      hibernate:
        ddl-auto: update # (for dev only)
      show-sql: true
    
    
  • Use Postman to test the API. For example, for creating an entry in the table (it is named cloud_vendor_info), paste the following in the Body (raw) field of POST request (at http://localhost:8080/cloudvendors) and hit 'Send':
    {
      "vendorName": "ABC",
      "vendorId": "Vendor 1",
      "vendorAddress": "PQR",
      "vendorPhoneNumber": "123-456-7890"
    }
    
  • Similarly, try other operations (GET/PUT/DELETE)

About

A simple Java REST API project demonstrating the Controller, Service and Repository layers for implementing CRUD operations in a MySQL DB, using Springboot and Spring Data JPA. (credits: https://www.youtube.com/watch?v=RfHBm5yRxuw)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages