When implementing a reactive endpoint, is there any difference between returning Uni<List<T>>
vs Multi<T>
?
@Path("/fruits")
public class FruitResource {
@GET
@Path("uni")
public Uni<List<Fruit>> getUni() {
return Fruit.listAll();
}
@GET
@Path("multi")
public Multi<Fruit> getMulti() {
return Fruit.streamAll();
}
}
I find it easier to use a Multi
because I can simply transform each each element to a DTO using onItem().transform(fruit -> ...)
With an Uni
, I would get a List
in the transform
method which is less convenient.
In all Quarkus guides, I see they are using a Uni<List>>
, is there any good reason for using this rather than a Multi
?