Annotation Type Headers


@Documented @Retention(RUNTIME) @Target(METHOD) public @interface Headers
Sets one or more fixed HTTP headers on every call of the annotated method, each given as a "Name: Value" string - for a header whose value is always the same (e.g. Accept, Cache-Control), not derived from a call argument. Use HeaderParam/HeaderMap instead for a header whose value varies per call; the two can be combined on the same method, with HeaderParam/HeaderMap overriding a @Headers entry of the same name, since the per-call value is more specific.

Each entry is split on its first ':', with whitespace around the name and value trimmed - "Name:Value", "Name: Value", "Name : Value", "Name :Value", and "Name : Value" are all equivalent. An entry with no ':', or an empty name, fails validation.

 @Headers({ "Cache-Control: no-cache", "X-Api-Version: 2" })
 @GET("/users")
 List<User> listUsers();
 
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The fixed headers to set, each as a "Name: Value" string.
  • Element Details

    • value

      String[] value
      The fixed headers to set, each as a "Name: Value" string.
      Returns:
      the header entries