spring-projects / spring-projects/spring-hateoas
Reactive Support in Spring HATEOAS documentation
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
Description
I am trying to use spring hateoas in a reactive application.
The documentation is still a todo tag, so I explored the code myself and I'm having a hard time to understand how that is supposed to be used.
In regular webMVC workd I have the model assemblers that create an entitymodel or the collection in a blocking fashion.
In reactive I have Mono and Flux as returntypes.
Mono should be easy, Mono<EntityModel>, so basically I just add a map(...) to the producing chain to create the wrapper as soon as the entity is present.
But the WebFluxBuilder.linkTo returns a Mono, which I don't understand at all. It fetches information readily present on the system and there is no need in any way to return a mono, it just could return the links based on the provided information.
So I end up doing something like that:
@Component
public class ContentItemResourceAssembler implements ReactiveRepresentationModelAssembler<ContentItem, EntityModel<ContentItem>> {
@Override
public Mono<EntityModel<ContentItem>> toModel(ContentItem entity, ServerWebExchange exchange) {
return Mono.just(EntityModel.of(entity,
linkTo(methodOn(ContentReadController.class).getItems(entity.getTenantId(), entity.getId())).withSelfRel().toMono().block(),
linkTo(methodOn(ContentBrowseController.class).getItems(entity.getTenantId(), null)).withRel("whatever").toMono().block()
));
}
}
It gets worse with collections, the assembler consumes a flux and returns a mono of the collectionModel with the items, which I assume is due to the fact that there is currently no elegant way to return surrounding wrapper with a streamed content. So basically no streaming, when you want to return the collection with collection links.
I assume to be able to have a special Flux with links which remains reactive, but is able to pass the surrounding links would require to enhance the reactor code to allow the reactive part to happen in a deeper nested part of the answer. Am I right?
So basically my "problem" boils down to:
- Why does the webflux linkto return reactive types?
- Wouldn't it make sense to support the flux to flux<EntityModel> case somehow to have that in an easy way?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reactive documentation todo, ReactiveRepresentationModelAssembler, and WebFluxBuilder.linkTo described in the issue. Document why linkTo returns reactive types and clarify the supported Mono and Flux collection patterns, including whether surrounding collection links can remain reactive. Done means the reactive usage and collection behavior are explained clearly with guidance for the cases raised here.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100