Retrofit: Feature Request. Add absolute url request

Created on 8 Aug 2018  路  5Comments  路  Source: square/retrofit

Feature Request

@Url annotation hidden combining with baseUrl is a non-intuitive way.
For instance it doesn't allow request for dynamic urls - if there is no scheme provided, it adds baseUrl which breaks request.

Also for purposes of combining baseUrl with multiple paths - there are already paths in @Get, @Post annotations and @Path param.

Suggestions:

  • Add new annotation @RelativeUrl and move there current @Url combining logic

    • Or even multiple annotations for each kind of combining (host relative, scheme relative, etc)

  • Make @Url always work as absolute url.

Or kind of workaround:

  • Add new annotation @AbsoluteUrl that will always work as absolute url.
Needs Info

Most helpful comment

Then you should be using OkHttp's API directly instead of Retrofit. Retrofit is for structured APIs and URLs known at compile-time.

All 5 comments

Can you provide a specific example that doesn't work? Relative resolution, absolute resolution, full URLs all work today.

non-intuitive way

It's the same as <a href=""> and pretty standard faire for resolving one URI against another.

@JakeWharton
As I wrote, specific example:

if there is no scheme provided, it adds baseUrl which breaks request.

When fetching web url without scheme (link preview on user provided data functionality) - url is prefixed with baseUrl, and as I can see for now - there is no way to keep url as it was provided by the user

Some ways to resolve URLs that already works with Retrofit:

https://example.com/path : full URL
//example.com/path : scheme-relative
/path : absolute path
path : relative path

We didn't invent this for Retrofit. It's how URLs work.

@swankjesse As I wrote - I need an option to open any url as absolute url, no matter the content - it's user provided data.

Then you should be using OkHttp's API directly instead of Retrofit. Retrofit is for structured APIs and URLs known at compile-time.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MetaiR picture MetaiR  路  3Comments

colintheshots picture colintheshots  路  3Comments

bolds07 picture bolds07  路  3Comments

vkislicins picture vkislicins  路  3Comments

chriskessel picture chriskessel  路  3Comments