Comment on page
Requests & Responses
Angel is inspired by Express, and such, request handlers in general resemble those from Express. Request handlers can return any Dart object (see how they are handled). Basic request handlers accept two parameters:
RequestContext- Contains vital information about the client requesting a resource, such as request method, request body, IP address, etc. The request object can also be used to pass information from one handler to the next.
Request handlers can return any Dart value. Return values are handled as follows:
- If you return a
bool: Request handling will end prematurely if you return
false, but it will continue if you return
RequestHandler: the returned handler will be executed.
toListwill be called, and then returned.
Future: it will be awaited, and then returned.
- Anything else: Whatever other Dart value you return will be serialized as a response. The default method is to encode responses as JSON, using
json.encode. However, you can change a response's serialization method by setting
res.serializer = foo;. If you want to assign the same serializer to all responses, globally set
serializeron your Angel instance. If you are only returning JSON-compatible Dart objects, like Maps or Lists, you might consider injecting
JSON.encodeas a serializer, to improve runtime performance (this is the default in
You can access a mutable
Mapbased on the URI query parameters by calling
For more information, see the API docs: