I have a particular web service that has the following POST URL:
(host)/pois/category?lat=...&long=...
Where category can be three things (let's say "cat1", "cat2" or "cat3"), and lat and long are doubles with the user geolocation.
Since the URL is defined as an Annotation like
@POST("/pois/")
How can I add or set these parameters to my URL?
@Body – Sends Java objects as request body. @Field – send data as form-urlencoded. This requires a @FormUrlEncoded annotation attached with the method. The @Field parameter works only with a POST. @Field requires a mandatory parameter.
You should use @Query
annotation
for example for endpoint:
/pois/category?lat=...&long=..
Your client should look like example below:
public interface YourApiClient {
@POST("/pois/category")
Response directions(@Query("lat") double lat, @Query("long") double lng,...);
}
or if you want to use callback, client should look like example below:
public interface YourApiClient {
@POST("/pois/category")
void directions(@Query("lat") double lat, @Query("long") double lng,..., Callback<Response> callback);
}
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