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
  • APIDocumentable

Static Properties

defaultSinkType → Type

read-only

Static Methods

initializeApplication(ApplicationConfiguration config) → Future

One-time setup method for an application.

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

@override, read-only, inherited
hashCode → int

The hash code for this object.

read-only, inherited
logger Logger

read-only, inherited
nextController RequestController

read / write, 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

Operators

operator ==(other) → bool

The equality operator.

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 generatorFunction()) RequestController

A function that instantiates a RequestController to pass a Request to if this instance returns a Request from processRequest.

inherited
handleError(Request request, caughtValue, StackTrace trace) → Future<bool>

Sends an HTTP response for a request that yields an exception or error.

inherited
listen(Future<RequestOrResponse> requestControllerFunction(Request request)) RequestController

A closure that responds to or forwards a Request.

inherited
noSuchMethod(Invocation invocation) → dynamic

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

inherited
pipe(RequestController n) RequestController

The next RequestController to pass a Request to if this instance returns a Request from processRequest.

inherited
processRequest(Request req) → Future<RequestOrResponse>

Overridden by subclasses to modify or respond to an incoming request.

inherited
receive(Request req) → Future

The mechanism for delivering a Request to this controller for processing.

inherited
toString() → String

Returns a string representation of this object.

inherited
willSendResponse(Response response) → void

Executed prior to Response being sent.

inherited