customer

The purpose of this project is to understand how the microservices work and how the package structure is setup.

CustomerApplication.java

  • This class gets generated automatically by the spring initializer.
  • During initialization, the package was specified as guru.springframework.customer.customer

CustomerDto.java

  • This class is idenfieid as data transfer object and it is used to send the data from front end to backend.
  • The best place/package to put data transfer objects are in guru.springframework.customer.customer.web.model

CustomerController.java

  • This class is the rest controller.
  • The purpose of this class is to accept the rest requests from client (postman) and send the response to it.
  • @RequestMapping("/api/v1/customer") is the class level annotation that tells the microservice to accept this specific path segment and envoke this controller.
  • @RestController is the class level annotation that tells the springboot that this class is the rest controller and should be treated that way.
  • @GetMapping("/{customerId}") is the method level annotation which tells the springboot to map the get requests to this method.
    • http://localhost:8080/api/v1/customer/a5f27a92-d09a-4601-a05b-a28a7a76fd73 will be mapped to this method.
    • @PathVariable
      • public ResponseEntity getCustomer(@PathVariable("customerId") UUID customerId)
      • @PathVariable is mapping the method level value ({customerId}) to the method variable of customerId
      • No need to have @PathVariable if all the variables are the same but it is a good practice to have it.