spring-projects / spring-projects/spring-hateoas

Reactive Support in Spring HATEOAS documentation

Open
#1,762 9 comments 2 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.