retrofit / retrofit2 / Retrofit / Builder / baseUrl

baseUrl

fun baseUrl(baseUrl: URL!): Retrofit.Builder!
fun baseUrl(baseUrl: String!): Retrofit.Builder!

Set the API base URL.

See Also
#baseUrl(HttpUrl)

fun baseUrl(baseUrl: HttpUrl!): Retrofit.Builder!

Set the API base URL.

The specified endpoint values (such as with @GET) are resolved against this value using HttpUrl#resolve(String). The behavior of this matches that of an <a href=""> link on a website resolving on the current URL.

Base URLs should always end in /.

A trailing / ensures that endpoints values which are relative paths will correctly append themselves to a base which has path components.

Correct: Base URL: http://example.com/api/ Endpoint: foo/bar/ Result: http://example.com/api/foo/bar/

Incorrect: Base URL: http://example.com/api Endpoint: foo/bar/ Result: http://example.com/foo/bar/

This method enforces that baseUrl has a trailing /.

Endpoint values which contain a leading / are absolute.

Absolute values retain only the host from baseUrl and ignore any specified path components.

Base URL: http://example.com/api/ Endpoint: /foo/bar/ Result: http://example.com/foo/bar/

Base URL: http://example.com/ Endpoint: /foo/bar/ Result: http://example.com/foo/bar/

Endpoint values may be a full URL.

Values which have a host replace the host of baseUrl and values also with a scheme replace the scheme of baseUrl.

Base URL: http://example.com/ Endpoint: https://github.com/square/retrofit/ Result: https://github.com/square/retrofit/

Base URL: http://example.com Endpoint: //github.com/square/retrofit/ Result: http://github.com/square/retrofit/ (note the scheme stays 'http')