Let’s say I have a quarkus resource like the following:
@ApplicationScoped
@Path("/some")
public class SomeResource {
@Inject
SomeService service;
@POST
@Path("/path")
@Produces(MediaType.SERVER_SENT_EVENTS)
@Consumes(MediaType.APPLICATION_JSON)
@RestStreamElementType(MediaType.APPLICATION_JSON)
public Multi<SomeResponse> streamResponses(@Body SomeRequest someRequest) {
return service.stream(someRequest);
}
}
and the SomeRequest class can contain a flag called stream, which indicates if the response should be streamed or returned as bulk json request. The service already has the capability to return bulk json. How can i return bulk responses or stream responses on the same route depending on the stream flag?
The resource with the additional endpoint should look something like this:
@ApplicationScoped
@Path("/some")
public class SomeResource {
@Inject
SomeService service;
@POST
@Path("/path")
@Produces(MediaType.SERVER_SENT_EVENTS)
@Consumes(MediaType.APPLICATION_JSON)
@RestStreamElementType(MediaType.APPLICATION_JSON)
public Multi<SomeResponse> streamResponses(@Body SomeRequest someRequest) {
return service.stream(someRequest);
}
@POST
@Path("/path")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public SomeResponse streamResponses(@Body SomeRequest someRequest) {
return service.chat(someRequest);
}
}
I have tried to use Reactive Routes, but could not find out how to conditionally set the return type correctely. Using a Uni resulted in the wrong content-type of the response
New contributor