Consuming REST APIs Using Reactor With Java Spring and WebClient

Suren K
TechInPieces
Published in
2 min readMar 26, 2020

--

In Spring 5, a reactive web client was introduced that access REST API’s in a reactive, non-blocking way. An improvement over the much used RestTemplate. This can be also closed compared to RxJs or Angular’s HttpClient to access REST API’s.

TL;DR

This article discusses about using Reactive programming to access API’s within Spring framework.

Build

  1. Build a new project using https://start.spring.io/ . Used Spring Web and Spring Reactive Web as dependencies

2. Unzip the downloaded package, and run $mvn spring-boot:run command at the root folder to make sure the default project builds and runs without any errors.

Should see something like this

3. We will use the sample REST API from https://jsonplaceholder.typicode.com/

A call to https://jsonplaceholder.typicode.com/todos/1 shows the following result:

{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}

4. Let’s add a POJO, Controller and a WebClient

--

--

Suren K
Suren K

Written by Suren K

Software Engineering Manager, Programmer, Architect, Inventor, Speaker and Writer. Works @Capgemini https://surenk.com