Lin icon indicating copy to clipboard operation
Lin copied to clipboard

Avoid relative or absolute urls mistakes when using retrofit

Open Tylos opened this issue 7 years ago • 0 comments

Retrofit endpoint definition is really easy and that is why it is so commonly used

@GET("group/{id}/users")
Call<List<User>> groupList(@Path("id") int groupId);

However, when declaring the URL within the annotation you can convert a relative URL into an absolute one just by adding a trailing slash. This small detail leads to unconscious errors, and unless you have already suffered it takes some time to notice.

https://github.com/square/retrofit/blob/ee72ada9bb9d227f133786a866606c019c349064/retrofit/src/main/java/retrofit2/Retrofit.java#L485-L496

Although there might be some endpoints that might differ, all URL should follow the same format so mixing absolute and relative URLs would be a Lin warning

Tylos avatar Dec 21 '18 10:12 Tylos