Binds an HTTP request body to an HTTPController property or responder method argument.

This metadata may be applied to a responder method argument or a property of an HTTPController. The body of an incoming request is decoded into the argument or property. The argument or property must implement HTTPSerializable or be a List<HTTPSerializable>. If the property or argument is a List<HTTPSerializable>, the request body must be decoded into a List of objects (i.e., a JSON array) and HTTPSerializable.readFromMap is invoked for each object.

Note that ManagedObject implements HTTPSerializable.

For example, the following controller will read a JSON object from the request body and assign its key-value pairs to the properties of User:

  class UserController extends HTTPController {
    @httpPost
    Future<Response> createUser(@HTTPBody() User user) async {
      var query = new Query<User)..values = user;

      ...
    }
  }

If a declaration with this metadata is a positional argument in a responder method, it is required for that method. e.g. the above example shows a required positional argument If a declaration with this metadata is an optional argument in a responder method, it is optional for that method. e.g. getUser({@HTTPQuery("since") DateTime timestamp}) async => ...; If a declaration with this metadata is a property without any additional metadata, it is optional for all methods in an HTTPController. If a declaration with this metadata is a property with requiredHTTPParameter, it is required for all methods in an HTTPController.

Requirements that are not met will be evoke a 400 Bad Request response with the name of the missing header in the JSON error body. No responder method will be called in this case. Validation only occurs if there is a request body.

If not required and not present in a request, the bound arguments and properties will be null when the responder method is invoked.

Inheritance
  • Object
  • HTTPBinding
  • HTTPBody

Constructors

HTTPBody()

Binds an HTTP request body to an HTTPController property or responder method argument.

const

Properties

type → String

@override, read-only
externalName → String

The name of the variable in the HTTP request.

final, inherited
hashCode → int

The hash code for this object.

read-only, inherited
runtimeType → Type

A representation of the runtime type of the object.

read-only, inherited

Operators

operator ==(other) → bool

The equality operator.

inherited

Methods

parse(ClassMirror intoType, Request request) → dynamic

convertParameterListWithMirror(List<String> parameterValues, TypeMirror typeMirror) → dynamic

inherited
convertParameterWithMirror(String parameterValue, TypeMirror typeMirror) → dynamic

inherited
noSuchMethod(Invocation invocation) → dynamic

Invoked when a non-existent method or property is accessed.

inherited
toString() → String

Returns a string representation of this object.

inherited