Search in sources :

Example 91 with retrofit2.http

use of retrofit2.http in project retrofit by square.

the class RequestBuilderTest method headerParamArray.

@Test
public void headerParamArray() {
    class Example {

        // 
        @GET("/foo/bar/")
        Call<ResponseBody> method(@Header("foo") String[] kit) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, (Object) new String[] { "bar", null, "baz" });
    assertThat(request.method()).isEqualTo("GET");
    okhttp3.Headers headers = request.headers();
    assertThat(headers.size()).isEqualTo(2);
    assertThat(headers.values("foo")).containsExactly("bar", "baz");
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
    assertThat(request.body()).isNull();
}
Also used : Header(retrofit2.http.Header) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 92 with retrofit2.http

use of retrofit2.http in project retrofit by square.

the class RequestBuilderTest method getWithQueryUrlAndParam.

@Test
public void getWithQueryUrlAndParam() {
    class Example {

        // 
        @GET("/foo/bar/?hi=mom")
        Call<ResponseBody> method(@Query("ping") String ping) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, "pong");
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/?hi=mom&ping=pong");
    assertThat(request.body()).isNull();
}
Also used : Query(retrofit2.http.Query) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 93 with retrofit2.http

use of retrofit2.http in project retrofit by square.

the class RequestBuilderTest method getWithEncodedQueryNameParam.

@Test
public void getWithEncodedQueryNameParam() {
    class Example {

        // 
        @GET("/foo/bar/")
        Call<ResponseBody> method(@QueryName(encoded = true) String ping) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, "p%20o%20n%20g");
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/?p%20o%20n%20g");
    assertThat(request.body()).isNull();
}
Also used : Request(okhttp3.Request) QueryName(retrofit2.http.QueryName) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 94 with retrofit2.http

use of retrofit2.http in project retrofit by square.

the class RequestBuilderTest method getWithQueryParamArray.

@Test
public void getWithQueryParamArray() {
    class Example {

        // 
        @GET("/foo/bar/")
        Call<ResponseBody> method(@Query("key") Object[] keys) {
            return null;
        }
    }
    Object[] values = { 1, 2, null, "three", "1" };
    Request request = buildRequest(Example.class, new Object[] { values });
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/?key=1&key=2&key=three&key=1");
    assertThat(request.body()).isNull();
}
Also used : Query(retrofit2.http.Query) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 95 with retrofit2.http

use of retrofit2.http in project retrofit by square.

the class RequestBuilderTest method getWithEncodedQueryParamMap.

@Test
public void getWithEncodedQueryParamMap() {
    class Example {

        // 
        @GET("/foo/bar/")
        Call<ResponseBody> method(@QueryMap(encoded = true) Map<String, Object> query) {
            return null;
        }
    }
    Map<String, Object> params = new LinkedHashMap<>();
    params.put("kit", "k%20t");
    params.put("pi%20ng", "p%20g");
    Request request = buildRequest(Example.class, params);
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/?kit=k%20t&pi%20ng=p%20g");
    assertThat(request.body()).isNull();
}
Also used : QueryMap(retrofit2.http.QueryMap) Request(okhttp3.Request) PartMap(retrofit2.http.PartMap) HashMap(java.util.HashMap) HeaderMap(retrofit2.http.HeaderMap) FieldMap(retrofit2.http.FieldMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) QueryMap(retrofit2.http.QueryMap) ResponseBody(okhttp3.ResponseBody) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)82 ResponseBody (okhttp3.ResponseBody)76 Request (okhttp3.Request)72 Retrofit (retrofit2.Retrofit)39 OkHttpClient (okhttp3.OkHttpClient)28 RequestBody (okhttp3.RequestBody)22 IOException (java.io.IOException)19 Query (retrofit2.http.Query)15 MultipartBody (okhttp3.MultipartBody)12 Buffer (okio.Buffer)12 Path (retrofit2.http.Path)12 Interceptor (okhttp3.Interceptor)11 HttpUrl (okhttp3.HttpUrl)10 Response (okhttp3.Response)10 HashMap (java.util.HashMap)9 LinkedHashMap (java.util.LinkedHashMap)9 Response (retrofit2.Response)9 Part (retrofit2.http.Part)9 List (java.util.List)8 QueryMap (retrofit2.http.QueryMap)8