Spring streaming response made easy
In this short article, we'll get into stream large size of data through stream as an alternative to the traditional endpoints.
Wed, 10th September 2025
Read MoreBlossoming Intelligence: How to Run Spring AI Locally with Ollama
In this short article, we'll look at how easy it is to create a chat bot backend powered by Spring and Olama using the llama 3 model.
Sat, 11th May 2024
Read MoreBlocking is a feature of classic servlet-based web frameworks like Spring MVC. Introduced in Spring 5, Spring WebFlux is a reactive framework that operates on servers like Netty and is completely non-blocking.
Two programming paradigms are supported by Spring WebFlux. Annotations (Aspect Oriented Programming) and WebFlux.fn (Functional Programming).
"Spring WebFlux includes WebFlux.fn, a lightweight functional programming model in which functions are used to route and handle requests and contracts are designed for immutability. It is an alternative to the annotation-based programming model but otherwise runs on the same Reactive Core foundation." Spring | Functional Endpoints
As the title describe, this is a simple Songs API build using Spring, Docker and MongoDB, the endpoints are Functional Endpoints and will have the traditional ControllerAdvice as Exception handler.
Talking XML these are the project dependencies:
First, let's setup the docker compose file /compose.yaml
of the project (it should generated by spring via the docker support starter).
With that set, let's create the Song class:
The SongRepository interface will be referring to the Song class in its DB ops:
Now, it's time for the Song Router, it will be responsible for router the incoming requests for the /songs ressource:
As you noticed the request are redirected to the SongHandler for a certain logic to be performed.
The SongsHandler will act as Service as well, will perform a business logic and communicate with the SongRepository for operations with the database.
As previously states, will be using the same old ControllerAdvice as Exception handler with two custom Exceptions as the following:
With all that been set, let's make use of our endpoint using Postman:
Sorry not a big fan of Madonna tbh :|
With that said, our functional songs endpoint will be good to go for further improvements and new features. This is simple, in real industrial projects, I can assure you it can get complicated with more layers, for "getting started" purposes I avoided the use of advanced concepts such as validation, DTO, etc.
You can find the full source code here