RequestSink class

Instances of this type are the root of an Aqueduct application.

Applications set up HTTP(S) listeners, but do not do anything with them. The behavior of how an application responds to requests is defined by its RequestSink. Must be subclassed. This class must be visible to the application library file for tools like aqueduct serve to run Aqueduct applications.

A RequestSink must implement its constructor and setupRouter. HTTP requests to the Application are added to a RequestSink for processing. The path the HTTP request takes is determined by the RequestController chains in setupRouter. A RequestSink is also a RequestController, but will always forward HTTP requests on to its initialController.

Multiple instances of this type will be created for an Application, each processing requests independently. Initialization code for a RequestSink instance happens in the constructor, setupRouter and willOpen - in that order. The constructor instantiates resources, setupRouter sets up routing and willOpen performs any tasks that occur asynchronously, like opening database connections. These initialization steps occur for every instance of RequestSink in an application.

Any initialization that occurs once per application cannot be performed in one of above methods. Instead, one-time initialization must be performed by implementing a static method in the RequestSink subclass named initializeApplication. This method gets executed once when an application starts, prior to instances of RequestSink being created. This method takes an ApplicationConfiguration, and may attach values to its ApplicationConfiguration.options for use by the RequestSink instances. This method is often used to read configuration values from a file.

The signature of this method is (ApplicationConfiguration) -> Future, for example:

    class MyRequestSink extends RequestSink {
      static Future initializeApplication(ApplicationConfiguration config) async {
        // Do one-time setup here, e.g read configuration values from a file
        var configurationValuesFromFile = ...;
        config.options = configurationValuesFromFile;


RequestSink(ApplicationConfiguration configuration)
Default constructor. [...]


apiInfo APIInfo
Documentation info for this instance.
read / write
configuration ApplicationConfiguration
Configuration options from the application. [...]
read / write
initialController RequestController
Returns the first RequestController to handle HTTP requests added to this sink. [...]
messageHub ApplicationMessageHub
Sends and receives messages to other isolates running a RequestSink. [...]
router Router
This instance's router. [...]
read / write
securityContext SecurityContext
The context used for setting up HTTPS in an application. [...]
server ApplicationServer
This instance's owning server. [...]
read / write
documentableChild APIDocumentable
Returns the next documentable object in a chain of documentable objects. [...]
read-only, inherited
hashCode int
The hash code for this object. [...]
read-only, inherited
logger Logger
An instance of the 'aqueduct' logger.
read-only, inherited
nextController RequestController
Receives requests that this controller does not respond to. [...]
read-only, inherited
policy CORSPolicy
The CORS policy of this controller.
read / write, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited


close() Future
Closes this instance. [...]
didOpen() → void
Executed after the instance is is open to handle HTTP requests. [...]
documentAPI(PackagePathResolver resolver) APIDocument
Returns an entire APIDocument describing an OpenAPI specification. [...]
setupRouter(Router router) → void
Callback for implementing this instances's routing table. [...]
willOpen() Future
Callback executed prior to this instance receiving requests. [...]
applyCORSHeadersIfNecessary(Request req, Response resp) → void
documentOperations(PackagePathResolver resolver) List<APIOperation>
Returns all APIOperations this object knows about.
documentPaths(PackagePathResolver resolver) List<APIPath>
Returns all APIPath objects this instance knows about. [...]
documentRequestBodyForOperation(APIOperation operation) APIRequestBody
Returns all APIRequestBodys for operation.
documentResponsesForOperation(APIOperation operation) List<APIResponse>
Returns all APIResponses for operation.
documentSecuritySchemes(PackagePathResolver resolver) Map<String, APISecurityScheme>
Returns all APISecuritySchemes this instance knows about.
generate(RequestController instantiator()) RequestController
Sets the nextController that will receive a request after this one. [...]
handleError(Request request, dynamic caughtValue, StackTrace trace) Future<bool>
Sends an HTTP response for a request that yields an exception or error. [...]
listen(FutureOr<RequestOrResponse> process(Request request)) RequestController
Sets the nextController that will receive a request after this one. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
pipe(RequestController next) RequestController
Sets the nextController that will receive a request after this one. [...]
processRequest(Request req) FutureOr<RequestOrResponse>
Overridden by subclasses to modify or respond to an incoming request. [...]
receive(Request req) Future
Delivers req to this instance to be processed. [...]
toString() String
Returns a string representation of this object.
willSendResponse(Response response) → void
Executed prior to Response being sent. [...]


operator ==(dynamic other) bool
The equality operator. [...]

Static Properties

defaultSinkType Type

Static Methods

initializeApplication(ApplicationConfiguration config) Future
One-time setup method for an application. [...]