use of retrofit2.http.Url in project retrofit by square.
the class RequestBuilderTest method getWithHttpUrl.
@Test
public void getWithHttpUrl() {
class Example {
@GET
Call<ResponseBody> method(@Url HttpUrl url) {
return null;
}
}
Request request = buildRequest(Example.class, HttpUrl.parse("http://example.com/foo/bar/"));
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url()).isEqualTo(HttpUrl.parse("http://example.com/foo/bar/"));
assertThat(request.body()).isNull();
}
use of retrofit2.http.Url in project retrofit by square.
the class RequestBuilderTest method getWithStringUrlAbsolute.
@Test
public void getWithStringUrlAbsolute() {
class Example {
@GET
Call<ResponseBody> method(@Url String url) {
return null;
}
}
Request request = buildRequest(Example.class, "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 RequestBuilderTest method postWithUrl.
@Test
public void postWithUrl() {
class Example {
@POST
Call<ResponseBody> method(@Url String url, @Body RequestBody body) {
return null;
}
}
RequestBody body = RequestBody.create(MediaType.parse("text/plain"), "hi");
Request request = buildRequest(Example.class, "http://example.com/foo/bar", body);
assertThat(request.method()).isEqualTo("POST");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar");
assertBody(request.body(), "hi");
}
use of retrofit2.http.Url in project retrofit by square.
the class RequestBuilderTest method getWithUrlThenQuery.
@Test
public void getWithUrlThenQuery() {
class Example {
@GET
Call<ResponseBody> method(@Url String url, @Query("hey") String hey) {
return null;
}
}
Request request = buildRequest(Example.class, "foo/bar/", "hey!");
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/?hey=hey!");
}
use of retrofit2.http.Url in project retrofit by square.
the class RequestBuilderTest method getWithJavaUriUrl.
@Test
public void getWithJavaUriUrl() {
class Example {
@GET
Call<ResponseBody> method(@Url URI url) {
return null;
}
}
Request request = buildRequest(Example.class, URI.create("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();
}
Aggregations