The shelf_rest library.

The shelf_rest library is a drop in replacement of shelf_route Router with the following additions:

  1. The shelf_bind HandlerAdapter is automatically installed so you can use ordinary Dart functions as handlers

  2. The shelf_bind annotations such as RequestBody are automatically available

  3. You can use annotations such as Get and Post in addition to the corresponding get and post methods on Router. These annotations are just another way of configuring the same thing and you can mix and match the two styles as you wish

  4. You can use the RestResource and ResourceMethod annotations to create your routes in a higher level, consistent manner

  5. You can add an argument to your handler methods of type ResourceLinksFactory to get a factory to help create HATEOAS links.

Constants

ALL_METHODS → dynamic

Used to specify that the Router should route requests to all HTTP methods for a given route

null

Typedefs

CustomObjectFactory(Request request) → dynamic

HandlerAdapter(Function handler) → Handler

a function that adapts a function to be a shelf Handler

IdExtractor(model) → dynamic

PathAdapter(path) → UriPattern

a function that adapts some representation of a path into the form UriPattern that is used internally

Printer(String s) → void

ResourceLinksFactoryFunction(resourceId, { bool includeSelf }) ResourceLinks

RouteableAdapter(Function handler) RouteableFunction

a function that adapts a function to be a RouteableFunction

RouteableFunction(DefaultRouterBuilder router) → dynamic

A function capable of creating routes in a given Router

ToMapDecoder(value, { ContentType requestContentType }) → Map

decodes a value into a Map

Properties

allMethods → Set<String>

read-only

Functions

appendToRoutingBreadCrumbs(Map context, Route route) RoutingContext

bind(Function handler, { Map<Type, CustomObjectFactory> customObjects, bool validateParameters: false, bool validateReturn: false }) → Handler

Bind properties (path parameters, body) of a Request to the parameters of a handler function.

bindManually(Function handler, { List<HandlerParameterBinding> parameterBindings: const [], ResponseBinding responseBinding, Map<Type, CustomObjectFactory> customObjects, bool validateParameters: false, bool validateReturn: false }) → Handler

Bind properties (path parameters, body) of a Request to the parameters of a handler function, by manually providing all the bindings.

formMapDecoder(String str, { ContentType requestContentType }) → Map

getPathParameter(Request request, String parameterName) → Object

Fetches a single path parameter from the given request with the given parameterName

getPathParameters(Request request) → Map<String, Object>

Fetches all the path parameters from the given request

getRoutingContext(Request request) → Option<RoutingContext>

Retrieves the current RoutingContext for the given Request or None

handlerAdapter({Map<Type, CustomObjectFactory> customObjects: const {}, bool validateParameters: false, bool validateReturn: false }) HandlerAdapter

Specify customObjects to support injection of arbitrary objects into your handler functions. When the binders encounter such parameters in your function it will call the factory you provide in customObjects instead of performing the normal binding process.

identityMapDecoder(Map map, { ContentType requestContentType }) → Map

jsonMapDecoder(String str, { ContentType requestContentType }) → Map

noopHandlerAdapter(Handler handler) → Handler

a HandlerAdapter that does nothing

noopRouteableAdapter(RouteableFunction routeable) RouteableFunction

a RouteableFunction that does nothing

printRoutes(Router router, { Printer printer: print }) → void

prints out a representation of all the routes within the router, using the printer if provided or the standard Dart print function if not.

requestContentTypeMapDecoder(String str, { ContentType requestContentType }) → Map

router({path, String name, HandlerAdapter handlerAdapter, RouteableAdapter routeableAdapter, PathAdapter pathAdapter: r.uriTemplatePattern, Function fallbackHandler, Middleware middleware }) Router

Creates a shelf_rest router builder.

Classes

Add

Annotation corresponding to the add method of Router For example, the following

AddAll

Annotation corresponding to the addAll method of Router For example, the following

BaseResponseBinding

BasicHandlerParameterBinding

The most common sort of HandlerParameterBinding

BindMode

Describes how the data (e. path parameters, form data) will be bound to the class.

BodyHandlerParameterSource

A HandlerParameterSource that extracts the data from the requests body

BoundHandlerAdapter

a HandlerAdapter for shelf_bind.

ComplexMapToObjectConverter

ComplexParameterTypeConverter

Converts the data for a handler parameter into another non simple class

ComplexRequestHandlerParam

ConstructorBasedMapToObjectConverter

A MapToObjectConverter that invokes a constructor (with default name of #build) of given class, mapping the names of constructor parameters, to request path parameters according to the associated TypeBinding

ContentType

Representation of a content type. An instance of ContentType is immutable.

ContentTypeBasedObjectConverter

CustomObjectParameterBinding

A HandlerParameterBinding that binds to a provided custom object using the associated CustomObjectFactory

DefaultLinksBuilder

DefaultResourceLinksFactory

DefaultRoute

The default implementation of Route. This is the most common kind of Route and is the basis of the core builders. Routing is done using the associated DefaultSegmentRouter which routes on the Request path and method

DefaultRoutePath

DefaultRouter

The default implementation of RequestRouter.

DefaultRouterBuilder

A SpecBasedRouterBuilder that defines a simple API for creating routes

DefaultSegmentRouter

The default implementation of SegmentRouter that routes based on the [Request] [path] and http methods

DefaultSimpleRoute

The default implementation of SimpleRoute.

Delete

Annotation corresponding to the delete method of Router For example, the following

Get

Annotation corresponding to the get method of Router For example, the following

HandlerBinding

A binding between an Dart Function and a [shelf] [Handler]

HandlerParameterBinding

Describes how a single parameter of a handler function is populated. It includes (either explicitly or implicitly) where the data comes from (almost always from the Request or derived from the request) and any transformations that are applied to that data.

HandlerParameterSource

Extracts the data for the handler parameter from Requests

HeaderHandlerParameterSource

A HandlerParameterSource that extracts the data from a single header field of the request

HeaderParam

Identified

IdentityMapToObjectConverter

Jsonable

JsonResponseBinding

JsonToObjectConverter

A MapToObjectConverter that invokes the #fromJson constructor of a given class

LinkHelper

LinkJsonHelper

LinksBuilder

MapBasedParameterTypeConverter

A ComplexParameterTypeConverter that uses a Map as an intermediate representation of the object. It uses an associated mapDecoder to first convert the data from the source form (typically a String) into a Map then passes the map into the associated converter to turn it into an object of the target type

MapToObjectConverter

converts a Map into some other Class

MemberBinding

MergeableHandlerAdapter

A HandlerAdapter that can be merged with another handlerAdapter of the same type

MultiPathHandlerParameterSource

A HandlerParameterSource that extracts the data from several path parameters

ParameterTypeConverter

Converts the data for a handler parameter into another type

PathHandlerParameterSource

A HandlerParameterSource that extracts the data from a single path parameter of the request

PathInfo

PathParam

An annotation that indicates that a handler parameter should be bound to a single request parameter.

PathParams

An annotation that indicates that a complex handler parameter should be bound to one or more request parameters.

Post

Annotation corresponding to the post method of Router For example, the following

Put

Annotation corresponding to the put method of Router For example, the following

RequestBody

An annotation that indicates that a handler parameter should be bound to the request body. Note that this annotation can often be omitted, as the default behaviour is for non basic types to be mapped to a JSON body. You should provide this annotation when you want to override this behaviour.

RequestHandlerParam

RequestObjectParameterBinding

A special CustomObjectParameterBinding for the Request class

RequestRouter

A Route that routes by attempting to route to a list of child Routes in order. The first Route that handles the request wins.

ResourceLinksBuilder

ResourceLinksFactory

ResourceMethod

An annotation on a class method that indicates it is a particular standard resource operation. This can be used to override the default naming scheme and HTTP method for operations on a RestResource as well as to customise the operation with custom Middleware.

ResourceModel

ResponseBinding

ResponseHeaders

Annotation to tweak default creating of responses

RestOperation

A class to identify the standard RestResource operations

RestResource

Class Annotation to indicate a REST resource with a given pathParameterName. REST resources typically follow a common pattern for the standard operations. For example a Books resource might look like

Route

The root of the Router hierarchy. A Route is something capable of routing a Request.

Routeable

A class capable of creating routes in a given Router. In most cases RouteableFunction is simpler and more compact

RouteAdapter

An adapter that converts a RouteSpec into a Route. The combination of pairs of RouteSpecs and their RouteAdapters provides a lot of flexibility in the creation of Routes

RouteAnnotation

Base class for all annotations that mimic the methods on Router. These support all the features for the corresponding methods and are therefore a complete alternative way to express the same

RoutePath

Router

A router builder for shelf_rest

RouterAdapter

An adapter that adapts an external form of a Router into an object of type Router. This allows other libraries to extend shelf_route

RouterBuilder

The base of all builders for RequestRouters

RouterSpec

Provides the data that will be used to create a RequestRouter. The routeAdapter if provided will be combined with existing adapters in the router and the result used to adapt the definition into a Router. routes must only contain objects of type RouterDefinition and SimpleRouteSpec

RouteSpec

An abstract specification of a Route. A RouteSpec requires a matching RouteAdapter to turn it into a Route.

RouteVisitor

Visitor pattern support

RoutingContext

Provides contextual information about the routing process. In particular it provides access to the currentRoute the request is passing through and to the path through the router hierarchy that the request has so far traveled (via routingBreadCrumbs)

SearchLinksBuilder

SearchResourceModel

SearchResult

SetterBasedMapToObjectConverter

A MapToObjectConverter that invokes an empty constructor of the given class, mapping the names of property setters to request path parameters according to the associated TypeBinding

SimpleParameterTypeConverter

Converts the data for a handler parameter into another simple type

SimpleRoute

A leaf node in the hierarchy. A SimpleRoute will route by checking if the Request matches the conditions for the route and if so handling the request directly

SimpleRouteAdapter

An adapter that adapts an external form of a SimpleRoute into an object of type SimpleRoute. This allows other libraries to extend shelf_route

SimpleRouteSpec

Provides the data that will be used to create a SimpleRoute. The routeAdapter if provided will be combined with existing adapters in the router and the result used to adapt the spec into a SimpleRoute. This includes adapting the handler into a Handler, the path into a UriPattern plus including any provided Middleware

SpecBasedRouterBuilder

a RouterBuilder that uses pairs of RouteSpec and RouteAdapter to define routes in an abstract, extensible way

TypeBinding

Exceptions / Errors

NotHandled

Thrown by a RequestRouter if no routes match the request