I'd like to perform batch request using Retrofit. It there any nice way, how to achieve it? Basically what I'm trying to do is to replace some characters in query part of URL (replace block is allowed only in path part of URL - using @Path
annotation).
Here is a pseudocode 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);
Yes, you can create two different Service instances.
Batch calls allow API applications to make multiple API calls within a single API call. In addition, each call can be tied to a different access_token meaning batch API calls work with multiple users. Batch calls allow your platform to accomplish more API interaction with less traffic, thus avoiding throttle limits.
You can pass parameter by @QueryMap Retrofit uses annotations to translate defined keys and values into appropriate format. Using the @Query("key") String value annotation will add a query parameter with name key and the respective string value to the request url .
@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) the exception message for attempting to use @Path
in the original question instructs you as to the right solution:
URL query string "client_id={client_id}&client_secret={client_secret}&v={v}&ll={ll}&intent={intent}&limit={limit}" must not have replace block. For dynamic query parameters use @Query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With