Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reactive rest client headers injection in Quarkus

Tags:

quarkus

I am following the guide of the new quarkus-resteasy-reactive-jackson extension to use it in an existing Quarkus application deployed in production.

In the Custom headers support section it's introduced the ClientHeadersFactory interface to allow injecting headers in a request, but you are forced to return a sync response. One can not use Uni<MultivaluedMap<String, String>>, which is of what is desired in my case, because I need to add a token in the header, and this token is retrieved by a request to another rest endpoint that returns a Uni<Token>.

How can I achieve this in the new implementation? If not possible, is there a workaround?

like image 894
AmsterdamLuis Avatar asked Oct 14 '25 09:10

AmsterdamLuis


1 Answers

It's not possible to use Uni<MultivaluedMap<...>> in ClientHeadersFactory in Quarkus 2.2.x (and older versions). We may add such a feature in the near future.

Currently, you can @HeaderParam directly. Your code could probably look as follows:

Uni<String> token  = tokenService.getToken();
token.onItem().transformToUni(tokenValue -> client.doTheCall(tokenValue));

Where the client interface would be something like:

@Path("/")
public interface MyClient {

    @GET
    Uni<Foo> doTheCall(@HeaderParam("token") String tokenValue);

}
like image 92
Michał Szynkiewicz Avatar answered Oct 17 '25 18:10

Michał Szynkiewicz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!