Avraham Shukron Avraham Shukron - 11 months ago 243
Android Question

Retrofit: How to send a POST request with constant fields?

I want to sent a simple POST request with one actual parameter:

void extendSession(@Field("refresh_token")final String refreshToken);

But this request should also send some constant values requested by the server such as
which are constant and should not be part of the application API.

What is the best way to do this?


It is matter of your approach. If you have the constants you can build a default Map of values required for your call. @FieldMap will be suitable for building a Map with all your required fields

private void extendSession(String token){
   Map params = buildDefaultParams();
   params.put("refreshToken", token);
private Map buildDefaultParams(){
   Map defaults = new HashMap();
   defaults.put("client_id", CLIENT_ID);
   defaults.put("client_secret", CLIENT_SECRET);
   defaults.put("grant_type", GRANT_TYPE);
   return defaults;
  /**then you change your interface to this **/ 
    void extendSession(@FieldMap() Map refreshToken);