use of retrofit2.http.Url in project retrofit by square.
the class DynamicBaseUrl method main.
public static void main(String... args) throws IOException {
HostSelectionInterceptor hostSelectionInterceptor = new HostSelectionInterceptor();
OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(hostSelectionInterceptor).build();
Retrofit retrofit = new Retrofit.Builder().baseUrl("http://www.coca-cola.com/").callFactory(okHttpClient).build();
Pop pop = retrofit.create(Pop.class);
Response<ResponseBody> response1 = pop.robots().execute();
System.out.println("Response from: " + response1.raw().request().url());
System.out.println(response1.body().string());
hostSelectionInterceptor.setHost("www.pepsi.com");
Response<ResponseBody> response2 = pop.robots().execute();
System.out.println("Response from: " + response2.raw().request().url());
System.out.println(response2.body().string());
}
use of retrofit2.http.Url in project retrofit by square.
the class RequestBuilderAndroidTest method getWithAndroidUriUrlAbsolute.
@Test
public void getWithAndroidUriUrlAbsolute() {
class Example {
@GET
Call<ResponseBody> method(@Url Uri url) {
return null;
}
}
Request request = buildRequest(Example.class, Uri.parse("https://example2.com/foo/bar/"));
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("https://example2.com/foo/bar/");
assertThat(request.body()).isNull();
}
use of retrofit2.http.Url in project retrofit by square.
the class RequestBuilderAndroidTest method getWithAndroidUriUrl.
@Test
public void getWithAndroidUriUrl() {
class Example {
@GET
Call<ResponseBody> method(@Url Uri url) {
return null;
}
}
Request request = buildRequest(Example.class, Uri.parse("foo/bar/"));
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
assertThat(request.body()).isNull();
}
use of retrofit2.http.Url in project retrofit by square.
the class RequestBuilderTest method getWithStringUrl.
@Test
public void getWithStringUrl() {
class Example {
@GET
Call<ResponseBody> method(@Url String url) {
return null;
}
}
Request request = buildRequest(Example.class, "foo/bar/");
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
assertThat(request.body()).isNull();
}
use of retrofit2.http.Url in project retrofit by square.
the class RequestBuilderTest method getWithJavaUriUrlAbsolute.
@Test
public void getWithJavaUriUrlAbsolute() {
class Example {
@GET
Call<ResponseBody> method(@Url URI url) {
return null;
}
}
Request request = buildRequest(Example.class, URI.create("https://example2.com/foo/bar/"));
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("https://example2.com/foo/bar/");
assertThat(request.body()).isNull();
}
Aggregations