Skip to content

Avoid relative or absolute urls mistakes when using retrofit #35

@Tylos

Description

@Tylos

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleNew rule for the detectors project

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions