Lab #1 - Building a basic Microservice with Spring Boot Steps: 1) using the Spring Tool Suite (STS), create a new project File -> new -> Project... -> Spring Boot -> Spring Starter Project with these values: Name: camino Type: Maven Java Version: 17 Packaging: Jar Language: Java Group: com.example.microservice Artifact: camino Version 0.0.01-SNAPSHOT Description: Package: com.example.microservice.camino click Next expand the Web section and select: Spring Web click Finish 2) examine the new project, and find: the main class the application.properties file the pom.xml file in STS (eclipse) I open Window->Properties->Maven and click Download Artifact JavaDoc 3) from the class web site, open the link to the data folder https://www.jre-training.com/Microservices/data/ and download the routes.yaml file into src/main/resources folder of your project 4) examine the routes.yaml file, and you will find a Route objects a Stage objects 5) in the project add a new package as a child package of the and com.example.microservice.camino created in step 1 create Route, Stage and RouteList classes in this new package Route has: private String name; private String code; private String nickname; private int count; private int length; private String description; private List stages; Stage has: private int stage; private String city; private String country; private double[] location; RouteList has: private List routes; add getter and setters for the fields 6) to convert the yaml data file into Java objects we will add a dependency to the pom.xml file com.fasterxml.jackson.dataformat jackson-dataformat-yaml 7) create a new Java class to encapsulate the data convertion name the class RouteService and add the @Service annotation to the class these lines of code will do the yaml to Java converion for you import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()) RouteList routeList = objectMapper.readValue(getClass().getResourceAsStream("/routes.yaml"), RouteList.class); 8) add 2 methods in the RouteService class to support: find all Routes find a specific Route by code you can add other methods as desired 9) you are now ready to create the Rest Endpoint(s) for the microservice create a Java class named RouteRestService and annotate it with @RestController 10) add 2 methods to support Rest API calls: bring in your RouteService instance via Spring Autowired @Autowired private RestService restService; @GetMapping(value="/routes", produces="application/json") List getRoutes() @GetMapping(value="/route/{code}", produces="application/json") Route getRouteByCode(@PathVariable String code) throws IOException; these method will call the RouteService to obtain the Java entities 11) run the main class as a Java Application and open a Browser to http://localhost:8080/routes or http://localhost:8080:/route/C1 Options: Can you add a new API endpoint to find a specific Stage? What happends if you ask for a Route that does not exist? Can you change the port number form 8080 to 9090?