Batch Request Using Retrofit

I want to execute a batch request using Retrofit. This is a good way there, how to achieve it? Basically, what I'm trying to do is replace some characters in the request part of the URL (replacing the block is allowed only in the part of the URL path using the @Path annotation).

Here is the pseudo code for my problem.

 @GET("/v2/multi?requests=/users/self,/venues/search?client_id={client_id}&client_secret={client_secret}&v={v}&ll={ll}&intent={intent}&limit={limit}") ProfileSearchVenuesResponse searchVenuesAndProfiles(@ReplaceBy("client_id") String clientId, @ReplaceBy("client_secret") String clientSecret, @ReplaceBy("v") int version, @ReplaceBy("ll") String location, @ReplaceBy("intent") String intent, @ReplaceBy("limit") int limit); 
+5
source share
1 answer

@Query is what you are looking for:

 @GET("/v2/multi?requests=/users/self,/venues/search") ProfileSearchVenuesResponse searchVenuesAndProfiles( @Query("client_id") String clientId, @Query("client_secret") String clientSecret, @Query("v") int version, @Query("ll") String location, @Query("intent") String intent, @Query("limit") int limit); 

In version 1.7.0 of Retrofit (released yesterday), an exception message for trying to use @Path in the original question gives you the correct solution:

The URL query string "client_id = {client_id} & client_secret = {client_secret} & v = {v} & ll = {ll} & target = {intent} & limit = {limit}" should not replace the block. For dynamic query parameters, use @Query.

+9
source

Source: https://habr.com/ru/post/1204376/


All Articles