A RequestController that implements basic CRUD operations for a ManagedObject.

Instances of this class map a REST API call directly to a database Query. For example, this RequestController handles an HTTP PUT request by executing an update Query; the path variable in the request indicates the value of the primary key for the updated row and the HTTP request body are the values updated.

When routing to a ManagedObjectController, you must provide the following route pattern, where can be any string:

  router.route("/<name>/[:id]")

You may optionally use the static method ManagedObjectController.routePattern to create this string for you.

The mapping for HTTP request to action is as follows:

  • GET //:id -> Fetch Object by ID
  • PUT //:id -> Update Object by ID, HTTP Request Body contains update values.
  • DELETE //:id -> Delete Object by ID
  • POST / -> Create new Object, HTTP Request Body contains update values.
  • GET / -> Fetch instances of Object

You may use this class without subclassing, but you may also subclass it to modify the executed Query prior to its execution, or modify the returned Response after the query has been completed.

The HTTP response body is encoded according to responseContentType.

GET requests with no path parameter can take extra query parameters to modify the request. The following are the available query parameters:

  • count (integer): restricts the number of objects fetched to count. By default, this is null, which means no restrictions.
  • offset (integer): offsets the fetch by offset amount of objects. By default, this is null, which means no offset.
  • pageBy (string): indicates the key in which to page by. See Query.pageBy for more information on paging. If this value is passed as part of the query, either pageAfter or pagePrior must also be passed, but only one of those.
  • pageAfter (string): indicates the page value and direction of the paging. pageBy must also be set. See Query.pageBy for more information.
  • pagePrior (string): indicates the page value and direction of the paging. pageBy must also be set. See Query.pageBy for more information.
  • sortBy (string): indicates the sort order. The syntax is 'sortBy=key,order' where key is a property of InstanceType and order is either 'asc' or 'desc'. You may specify multiple sortBy parameters.
Inheritance

Static Methods

routePattern(String name) → String

Returns a route pattern for using ManagedObjectControllers.

Constructors

ManagedObjectController([ManagedContext context ])

Creates an instance of a ManagedObjectController.

ManagedObjectController.forEntity(ManagedEntity entity, [ ManagedContext context ])

Creates a new ManagedObjectController without a static type.

Properties

acceptedContentTypes → List<ContentType>

Types of content this HTTPController will accept.

read / write, inherited
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
pathVariables → Map<String, String>

Parameters parsed from the URI of the request, if any exist.

read-only, inherited
policy CORSPolicy

The CORS policy of this controller.

read / write, inherited
request Request

The request being processed by this HTTPController.

read / write, inherited
responseContentType → ContentType

The default content type of responses from this HTTPController.

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

createObject() → Future<Response>

@httpPost
deleteObject(String id) → Future<Response>

@httpDelete
didDeleteObjectWithID(id) → Future<Response>

Executed after an object was deleted.

didFindObject(InstanceType result) → Future<Response>

Executed after a fetch by ID query that found a matching instance.

didFindObjects(List<InstanceType> objects) → Future<Response>

Executed after a list of objects has been fetched.

didInsertObject(InstanceType object) → Future<Response>

Executed after an insert query is successful.

didNotFindObject() → Future<Response>

Executed after a fetch by ID query that did not find a matching instance.

didNotFindObjectToDeleteWithID(id) → Future<Response>

Executed when no object was deleted during a delete query.

didNotFindObjectToUpdateWithID(id) → Future<Response>

Executed after an object not found during an update query.

didUpdateObject(InstanceType object) → Future<Response>

Executed after an object was updated.

documentRequestBodyForOperation(APIOperation operation) APIRequestBody

Returns all APIRequestBodys for operation.

documentResponsesForOperation(APIOperation operation) → List<APIResponse>

Returns all APIResponses for operation.

getObject(String id) → Future<Response>

@httpGet
getObjects({int count: 0, int offset: 0, String pageBy: null, String pageAfter: null, String pagePrior: null, List<String> sortBy: null }) → Future<Response>

@httpGet
updateObject(String id) → Future<Response>

@httpPut
willDeleteObjectWithQuery(Query<InstanceType> query) → Future<Query<InstanceType>>

Executed prior to a delete query being executed.

willFindObjectsWithQuery(Query<InstanceType> query) → Future<Query<InstanceType>>

Executed prior to a fetch query being executed.

willFindObjectWithQuery(Query<InstanceType> query) → Future<Query<InstanceType>>

Executed prior to a fetch by ID query.

willInsertObjectWithQuery(Query<InstanceType> query) → Future<Query<InstanceType>>

Executed prior to an insert query being executed.

willUpdateObjectWithQuery(Query<InstanceType> query) → Future<Query<InstanceType>>

Executed prior to a update query being executed.

applyCORSHeadersIfNecessary(Request req, Response resp) → void

inherited
didDecodeRequestBody(HTTPRequestBody decodedObject) → void

Callback to indicate when a request body has been processed.

inherited
documentAPI(PackagePathResolver resolver) APIDocument

Returns an entire APIDocument describing an OpenAPI specification.

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
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
willDecodeRequestBody(HTTPRequestBody body) → void

Callback invoked prior to decoding a request body.

inherited
willProcessRequest(Request req) → Future<RequestOrResponse>

Executed prior to handling a request, but after the request has been set.

inherited
willSendResponse(Response response) → void

Executed prior to Response being sent.

inherited