Difficulty: Beginner
Estimated Time: 20 minutes

Do you want to create a reactive Spring project? Then, you're at the right place!

This scenario builds on a previous scenario that sets up the front end API controller. If you haven't already done so, you may want to check it out.

In this scenario, we'll learn how to:

  • Set up an Astra (Cassandra as a Service) database
  • Create the reactive code to access the database
  • Connect the database access code to the API controller
  • Use Swagger UI to access the API

This scenario is a subset of the full Spring Pet Clinic Reactive project that focuses on a single entity. Note that Reactive programming is a bit more advanced, so it may be helpful to review the basic Spring Pet Clinic example in preparation for this scenario. Here's an architectural diagram.

Architectural Diagram

ver 0.003

We just created a Spring Reactive REST API using a single entity.

In this scenario, we learned how to:

  • Set up an Astra (Cassandra as a Service) database
  • Create the reactive code to access the database
  • Connect the database access code to the API controller
  • Use Swagger UI to access the API

This scenario focused on a single entity of the Reactive Spring Pet Clinic example to isolate and identify the necessary components. Check out the other scenarios in the Reactive Spring Pet Clinic course for further Spring Reactive ideas.

Build a Reactive Spring REST Service

Step 1 of 11

Try Out Swagger

In the previous scenario, we created a stubbed-out API controller that uses only a Hashtable as a backing store. In this scenario, we'll use that controller as a foundation and add a Cassandra reactive backend.

Let's start by running the controller from the previous scenario. Click the following.

export JAVA_HOME="/usr/lib/jvm/default-java"
cd /root/spring-petclinic-reactive
mvn spring-boot:run

You can read about, and exercise, this API using Swagger UI.

What is Swagger UI? Swagger UI is a tool that describes the API and allows us to interact with it. You can read more here.

Launch Swagger UI in a separate browser tab by clicking the following.

Expand the Owners API by clicking as shown.

Expand Owners API

From here, you can see the various REST operations. We'll start by retrieving all Owners (which is an empty list because we haven't added any Owners yet), just to see how the API works.

Expand the Get API by clicking as shown.

Expand Owners Get API

Click on Get's Try it out button as shown.

Get Try it out

Click on the Execute button.

Execute the Get operation

You see that the query returns an empty result set - as expected.

Get results

Let's add a record so we can see how that works.

Scroll down to the post button and click as shown.

Expand Post

Click the Try it out button as shown.

Post Try it out

Edit the values within the Request body by changing the five "string" sections to "The value of your choice". Be sure to only edit the values, not the keys (e.g., "address", "city", etc.). Also, be sure to keep double quotes surrounding the values. Finally, don't change the ID value.


NOTE: If you inspect the createOwner method in the OwnerReactiveController class, you will notice that the method assigns a randomly generated UUID to the newly created Owner. However, we still need to supply a valid UUID when we post the Owner. The response body contains the newly generated UUID value


When you're ready, click Execute as shown.

Post input

You can now scroll up to the Get section and re-execute that query to retrieve the new record from the service.

Take some time to try out the other API operations. When you need a UUID value, remember to use the one from the Post response body and not the value from the Post request body.

Great! We have the controller running!