Code summary

A Weather Microservice with a basic RESTful endpoint providing information about a city's average temperature has been created. There were two classes created, each with a unique role in the system:

  • WeatherMicroService
  • TemperatureResource

The WeatherMicroService class holds a minimalistic configuration of the Weather Microservice. It is required to explicitly state the basic context path of the Microservice URI.

The TemperatureResource class represents a specific resource within the Microservice itself. It contains one endpoint returning the mentioned average temperature in the city, represented by the getAverageTemperature() method. We introduced two additional pieces of metadata written in the form of an annotation:

  • The javax.ws.rs.Path annotation, which defines the path of the temperature resource. The path is relative to the application path defined in the WeatherMicroService class.
  • The javax.ws.rs.GET annotation, which tells us to user the  GET HTTP method to  make a call to getAverageTemperature() service.

With all these steps taken, the Microservice is entirely implemented and ready to be run.

The final outline of the project with packages and classes in {project-root}/src/main/java is demonstrated by the following directory tree:

com
└── packtpub
└── microservices
└── weather
├── temperature
│ └── TemperatureResource.java
└── WeatherApplication.java
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.189.228