🚀 Master the language of AI with our brand new course: "Prompt Engineering for Everyone" Learn more

Offered By: IBM

Consuming RESTful Java microservices with template interfaces using Eclipse MicroProfile Rest Client

Learn how to use MicroProfile Rest Client to invoke RESTful microservices over HTTP in a type-safe way.

Continue reading

Guided Project

Open Liberty

60 Enrolled

At a Glance

Learn how to use MicroProfile Rest Client to invoke RESTful microservices over HTTP in a type-safe way.

You will learn how to build a MicroProfile Rest Client to access remote RESTful services. You will create a template interface that maps to the remote service that you want to call. MicroProfile Rest Client automatically generates a client instance based on what is defined and annotated in the template interface. Thus, you don’t have to worry about all of the boilerplate code, such as setting up a client class, connecting to the remote server, or invoking the correct URI with the correct parameters.
The application that you will be working with is an inventory service, which fetches and stores the system property information for different hosts. Whenever a request is made to retrieve the system properties of a particular host, the inventory service will create a client to invoke the system service on that host. The system service simulates a remote service in the application.
You will instantiate the client and use it in the inventory service. You can choose from two different approaches, Context and Dependency Injection (CDI) with the help of MicroProfile Config or the RestClientBuilder method. In this guide, you will explore both methods to handle scenarios for providing a valid base URL.
  • When the base URL of the remote service is static and known, define the default base URL in the configuration file. Inject the client with a CDI method.
  • When the base URL is not yet known and needs to be determined during the run time, set the base URL as a variable. Build the client with the more verbose RestClientBuilder method.

Created by 

The Open Liberty Project team

Estimated Effort

20 Minutes

Level

Intermediate

Skills You Will Learn

Java

Language

English

Course Code

GPXX0XV3EN

Tell Your Friends!

Saved this page to your clipboard!

Sign up to our newsletter

Stay connected with the latest industry news and knowledge!