Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify use of Multi as return type in RESTEasy Reactive #14183

Closed
geoand opened this issue Jan 8, 2021 · 6 comments
Closed

Clarify use of Multi as return type in RESTEasy Reactive #14183

geoand opened this issue Jan 8, 2021 · 6 comments
Labels
area/rest kind/enhancement New feature or request
Milestone

Comments

@geoand
Copy link
Contributor

geoand commented Jan 8, 2021

Description
Currently RESTEasy Reactive always tries to "stream" a result when Multi is used a return type of Resource method.

This can be surprising in cases like the following:

@Path("fruits")
@ApplicationScoped
@Produces("application/json")
@Consumes("application/json")
public class FruitMutinyResource {
    private static final Logger LOGGER = Logger.getLogger(FruitMutinyResource.class.getName());

    @Inject
    Mutiny.Session mutinySession;

    @GET
    public Multi<Fruit> get() {
        return mutinySession
                .createNamedQuery( "Fruits.findAll", Fruit.class ).getResults();
    }

}

where users expect to get a JSON array as a result, but instead end up with something like

{"id":2,"name":"Apple"}{"id":3,"name":"Banana"}{"id":1,"name":"Pineapple"}

We have the following options:

  • Keep things as they are (as in Multi always "streams") and expect users to collect the results to Uni (using .collectItems().asList() on the Multi)
  • Have RESTEasy Reactive automatically collect the result to Uni when the media type of resource method does not support streaming (for example application/json does not stream). This may not be bullet-proof however as there is no spec mandate about which media types can and can't stream.

Historical note

The discussion that lead to this is here

@geoand geoand added the kind/enhancement New feature or request label Jan 8, 2021
@ghost ghost added the area/rest label Jan 8, 2021
@ghost
Copy link

ghost commented Jan 8, 2021

/cc @FroMage, @stuartwdouglas

@FroMage
Copy link
Member

FroMage commented Jan 8, 2021

Technically, we can stream json arrays too, as long as we start with [ and separate them with , and end with ], with the application/json mime type: that's just raw HTTP streaming since the end result is a valid json value.

We could just do that and call it a day. Then it's up to the client to figure out if it wants to stream or not.

@cescoffier
Copy link
Member

+1

If someone tells me how this should be done, I will be happy to implement it (well, reuse the code I wrote for reactive routes).

@FroMage
Copy link
Member

FroMage commented Jan 11, 2021

#14214 should fix this.

@cescoffier
Copy link
Member

Shouldn't we close that issue? PR #14214 has been merged.

@geoand @FroMage

@geoand
Copy link
Contributor Author

geoand commented Feb 22, 2021

Yes, let's close it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants