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;
      }
      ...
    }
Inheritance
Implements

Constructors

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

Properties

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. [...]
read-only
messageHub ApplicationMessageHub
Sends and receives messages to other isolates running a RequestSink. [...]
final
router Router
This instance's router. [...]
read / write
securityContext SecurityContext
The context used for setting up HTTPS in an application. [...]
read-only
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

Methods

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
inherited
documentOperations(PackagePathResolver resolver) List<APIOperation>
Returns all APIOperations this object knows about.
inherited
documentPaths(PackagePathResolver resolver) List<APIPath>
Returns all APIPath objects this instance knows about. [...]
inherited
documentRequestBodyForOperation(APIOperation operation) APIRequestBody
Returns all APIRequestBodys for operation.
inherited
documentResponsesForOperation(APIOperation operation) List<APIResponse>
Returns all APIResponses for operation.
inherited
documentSecuritySchemes(PackagePathResolver resolver) Map<String, APISecurityScheme>
Returns all APISecuritySchemes this instance knows about.
inherited
generate(RequestController instantiator()) RequestController
Sets the nextController that will receive a request after this one. [...]
inherited
handleError(Request request, dynamic caughtValue, StackTrace trace) Future<bool>
Sends an HTTP response for a request that yields an exception or error. [...]
inherited
listen(FutureOr<RequestOrResponse> process(Request request)) RequestController
Sets the nextController that will receive a request after this one. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
pipe(RequestController next) RequestController
Sets the nextController that will receive a request after this one. [...]
inherited
processRequest(Request req) FutureOr<RequestOrResponse>
Overridden by subclasses to modify or respond to an incoming request. [...]
inherited
receive(Request req) Future
Delivers req to this instance to be processed. [...]
inherited
toString() String
Returns a string representation of this object.
inherited
willSendResponse(Response response) → void
Executed prior to Response being sent. [...]
inherited

Operators

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

Static Properties

defaultSinkType Type
read-only

Static Methods

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