Retrofit: Default values for @Path and @Query annotations

Created on 9 Aug 2013  路  1Comment  路  Source: square/retrofit

What do you think about adding optional default values to @Path and @Query annotations?

In issue #210 there was discussion about what to do with null value. Maybe if default value is present - add it in case of null?

public interface API {
    @GET("/user/{id}")
    void getUser(
            @Path("id", 1) String userId
    );
}

Additionally (I'm not sure if it is possible) it would be great to call just api.getUser() for defaults.

Most helpful comment

Default values should probably be handled the same was as you would with normal Java objects: method overloading.

public interface API {
  @GET("/user/1")
  void getUser();

  @GET("/user/{id}")
  void getUser(@Path("id") String userId);
}

>All comments

Default values should probably be handled the same was as you would with normal Java objects: method overloading.

public interface API {
  @GET("/user/1")
  void getUser();

  @GET("/user/{id}")
  void getUser(@Path("id") String userId);
}
Was this page helpful?
0 / 5 - 0 ratings