retrofit / retrofit2.http

Package retrofit2.http

Annotations

Body

class Body

Use this annotation on a service method param when you want to directly control the request body of a POST/PUT request (instead of sending in as request parameters or form-style request body). The object will be serialized using the Retrofit instance Converter and the result will be set directly as the request body.

DELETE

class DELETE

Make a DELETE request.

Field

class Field

Named pair for a form-encoded request.

FieldMap

class FieldMap

Named key/value pairs for a form-encoded request.

FormUrlEncoded

class FormUrlEncoded

Denotes that the request body will use form URL encoding. Fields should be declared as parameters and annotated with @Field.

GET

class GET

Make a GET request.

HEAD

class HEAD

Make a HEAD request.

Header

class Header

Replaces the header with the value of its target.


  @GET("/")
  Call<ResponseBody> foo(@Header("Accept-Language") String lang);
  
Header parameters may be null which will omit them from the request. Passing a or array will result in a header for each non-null item.

HeaderMap

class HeaderMap

Adds headers specified in the Map or okhttp3.Headers.

Headers

class Headers

Adds headers literally supplied in the value.


  @Headers("Cache-Control: max-age=640000")
  @GET("/")
  ...
 
  @Headers({
    "X-Foo: Bar",
    "X-Ping: Pong"
  })
  @GET("/")
  ...
  
Note: Headers do not overwrite each other. All headers with the same name will be included in the request.

HTTP

class HTTP

Use a custom HTTP verb for a request.


  interface Service {
    @HTTP(method = "CUSTOM", path = "custom/endpoint/")
    Call<ResponseBody> customEndpoint();
  }
  
This annotation can also used for sending DELETE with a request body:

  interface Service {
    @HTTP(method = "DELETE", path = "remove/", hasBody = true)
    Call<ResponseBody> deleteObject(@Body RequestBody object);
  }
  

Multipart

class Multipart

Denotes that the request body is multi-part. Parts should be declared as parameters and annotated with @Part.

OPTIONS

class OPTIONS

Make an OPTIONS request.

Part

class Part

Denotes a single part of a multi-part request.

PartMap

class PartMap

Denotes name and value parts of a multi-part request.

PATCH

class PATCH

Make a PATCH request.

Path

class Path

Named replacement in a URL path segment. Values are converted to strings using (or Object#toString(), if no matching string converter is installed) and then URL encoded.

POST

class POST

Make a POST request.

PUT

class PUT

Make a PUT request.

Query

class Query

Query parameter appended to the URL.

QueryMap

class QueryMap

Query parameter keys and values appended to the URL.

QueryName

class QueryName

Query parameter appended to the URL that has no value.

Streaming

class Streaming

Treat the response body on methods returning ResponseBody as is, i.e. without converting the body to byte[].

Tag

class Tag

Adds the argument instance as a request tag using the type as the key.


  @GET("/")
  Call<ResponseBody> foo(@Tag String tag);
  
Tag arguments may be null which will omit them from the request. Passing a parameterized type such as List<String> will use the raw type (i.e., List.class) as the key. Duplicate tag types are not allowed.

Url

class Url

URL resolved against the base URL.


  @GET
  Call<ResponseBody> list(@Url String url);