Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrofit POST URL with parameters

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?

like image 755
Teo Inke Avatar asked Mar 12 '15 15:03

Teo Inke


People also ask

What is field in retrofit?

@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.


1 Answers

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);
}
like image 144
Konrad Krakowiak Avatar answered Oct 25 '22 04:10

Konrad Krakowiak