Header

@Target(allowedTargets = [AnnotationTarget.FUNCTION])
annotation class Header(@Language(value = "http-header-reference") val name: String, val value: String)

Add a header to a request

@Header("Accept", "application/json")
@Header("Content-Type", "application/json")
@POST("comments")
suspend fun request(@Body comments: List<Comment>): List<Comment>

// type-safe
@Header(Header.Accept, Header.ContentTypes.Application.Json)
@GET("comments")
suspend fun request(): List<Comment>

By default, Headers do not overwrite each other: all headers with the same name will be included in the request. Except headers mentioned as singleton, e.g. Content-Type

Migration from other libraries: Use @HeaderParam for parameters

See also

Types

Link copied to clipboard

Contain commonly used Accept-Encoding values.

Link copied to clipboard
object Companion

Contain most used headers name

Link copied to clipboard

Contain common types of header Content-Type subdivide in objects as Type/Subtype

Properties

Link copied to clipboard

The header name

Link copied to clipboard

The header value