retrofit / retrofit2.http / Field

Field

@Target([AnnotationTarget.VALUE_PARAMETER]) class Field

Named pair for a form-encoded request.

Values are converted to strings using Retrofit#stringConverter(Type, Annotation[]) (or Object#toString(), if no matching string converter is installed) and then form URL encoded. null values are ignored. Passing a List or array will result in a field pair for each non-null item.

Simple Example:


  @FormUrlEncoded
  @POST("/")
  Call<ResponseBody> example(
      @Field("name") String name,
      @Field("occupation") String occupation);
  
Calling with foo.example("Bob Smith", "President") yields a request body of name=Bob+Smith&occupation=President.

Array/Varargs Example:


  @FormUrlEncoded
  @POST("/list")
  Call<ResponseBody> example(@Field("name") String... names);
  
Calling with foo.example("Bob Smith", "Jane Doe") yields a request body of name=Bob+Smith&name=Jane+Doe.

See Also
FormUrlEncodedFieldMap

Constructors

<init>

Field(value: String, encoded: Boolean)

Named pair for a form-encoded request.

Properties

encoded

val encoded: Boolean

Specifies whether the name and value are already URL encoded.

value

val value: String