Invoking the Microservice

For each successfully deployed application, Payara Micro prints information about the URI the application can be accessed under, as well as a list of REST endpoints exposed by the application and their URLs.

After invoking java -jar payara-micro-4.1.2.172.jar --deploy {deployment-name}.{jar|war|ear} from the command line, the output at the very end of the Payara Micro startup process contains the following information:

Payara Micro URLs
http://localhost:8080/weather-service-1.0

'weather-service-1.0' REST Endpoints
GET /weather-service-1.0/weather/temperature

With Payara Micro and the Weather Microservice up and running, the Microservice itself can be invoked. From the console output provided by Payara Micro, the final path, or more precisely the URL of the average temperature endpoint, can be assembled.

Payara Micro, as the majority of other Microservice solutions, binds to the localhost interface on port 8080 by default. The so-called context part of the URL is composed of several parts. The URL parts for the Temperature resource are composed as follows:

  • /weather-service-1.0 : This represents the name of the Java Web Archive deployed to Payara Micro. This part can be removed by renaming the deployment unit to ROOT.{jar|war|ear}.
  • /weather : This represents the base context path for all Weather Microservice RESTful endpoints, as defined in the WeatherMicroservice class.
  • /temperature : This represents the path to the final temperature resource, as defined by the TemperatureResource class in the code.

The final URL for the average temperature resource is derived from the preceding information to create the following URL:

http://localhost:8080/weather-service-1.0/weather/temperature

As expected, the endpoint is reachable by means of an HTTP protocol. To invoke the Microservice, a tool able to make requests with the HTTP protocol is required. A widespread utility, named cURL (to download, check out https://curl.haxx.se/download.html), is capable, in its own words, of transferring data to and from a server while using many protocols, and HTTP is one of them. Invoking the endpoint with cURL means passing the URL of the average temperature endpoint to the utility:

> curl http://localhost:8080/weather-service-1.0/weather/temperature
{"temperature":60.0,"temperatureScale":"CELSIUS"}

The Weather Microservice immediately responds with the temperature in JSON format.

cURL automatically recognizes the protocol from the URL passed as a parameter. Also, when no HTTP method is specified, cURL uses the HTTP GET method by default. As the endpoint is available via HTTP GET, this is desired behavior.
..................Content has been hidden....................

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