RequestHeader class

Binds a method parameter to an HTTP header of the request.

Use it for values that travel in headers rather than in the path or the body: a request id, a tenant, an API version, a token. On a controller, the server reads the header and converts it to the parameter's type; a List takes all its values. On a Feign client, the argument is sent as that header, replacing a value of the same name from the mapping's headers. Without a name, the parameter's own name is the header name. A Map<String, ...> parameter stands for all headers: a server fills it with every header of the request, a client sends one header per entry. On a server, an HttpHeaders parameter gets all headers too.

Whether a value is required follows the Dart parameter, as for RequestParam: nullable (String? tenant) or with a default ({String tenant = 'public'}) is optional, anything else is required (a missing header is a 400 on a server).

// The caller's id for the request, echoed into the logs.
@PostMapping('/orders')
Future<Order> place(
  @RequestBody() Order order,
  @RequestHeader('X-Request-Id') String requestId,
) => orders.place(order, requestId: requestId);

// Requests without X-Tenant use the public tenant.
@GetMapping('/orders')
Future<List<Order>> list({
  @RequestHeader('X-Tenant') String tenant = 'public',
}) => orders.list(tenant);

Spring (Java), with defaultValue where Dart uses a default value:

Order place(@RequestBody Order order,
    @RequestHeader("X-Request-Id") String requestId) { ... }
List<Order> list(
    @RequestHeader(name = "X-Tenant", defaultValue = "public")
    String tenant) { ... }

Constructors

RequestHeader([String? name])
Binds the header name; without one, the header named like the parameter.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
name → String?
The header name, or null to use the parameter's name.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited