liveBook · Manning

bodyToFlux()

As explained in Spring in Action, Sixth Edition

bodyToFlux() is a WebClient response operation that converts a response body into a Flux of a specified type.

bodyToFlux() extracts a WebClient response body as a Flux of a specified type. Use it when one request returns multiple items, such as a collection of ingredients. section 12.4.1

Flux<Ingredient> ingredients = WebClient.create()
    .get()
    .uri("http://localhost:8080/ingredients")
    .retrieve()
    .bodyToFlux(Ingredient.class);
 
ingredients.subscribe(i -> { ... });

This request retrieves all ingredients and converts the response into a Flux<Ingredient>. The Flux remains lazy: apply operations such as filtering or mapping, then subscribe so the request is sent and data begins flowing. section 12.4.1

The operation commonly follows get(), uri(), and retrieve(). Unlike bodyToMono(), which produces one value, bodyToFlux() produces a stream of values. For advanced response handling, exchangeToFlux() exposes ClientResponse objects instead, including response metadata such as headers and cookies. section 12.4.1 section 12.4.5

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains typed extraction, deferred subscription, and downstream operations, but stops short of implementation internals.
Examples
Demonstrates fetching all ingredients from an /ingredients endpoint and subscribing to each result.
What it assumes
Assumes basic WebClient request construction and distinguishes Flux from the single-value Mono type.
What you can do after
Apply it via WebClient to retrieve multiple typed response items and compose reactive operations before subscription.
How it connects
Connects WebClient, Flux, Mono, retrieve(), ResponseSpec, and exchangeToFlux().

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.