shelf_plus library
Shelf Plus is a quality of life addon for your server-side development within the Shelf platform.
Classes
- Cascade
- A helper that calls several handlers in sequence and returns the first acceptable response.
- Pipeline
- A helper that makes it easy to compose a set of Middleware and a Handler.
- Request
- An HTTP request to be processed by a Shelf application.
- RequestBodyAccessor
- Reference class for different request body accessors. Provides basic accessors like asString or asJson.
- Response
- The response returned by a Handler.
- Route
-
Annotation for handler methods that requests should be routed when using
package
shelf_router_generator
. - Router
- A shelf Router routes requests to handlers based on HTTP verb and route pattern.
- RouterPlus
- Extended request router based on shelf Router
- Server
- An adapter with a concrete URL.
- ServerHandler
- A connected pair of a Server and a Handler.
- ShelfRunContext
- WebSocketSession
- Abstraction of a websocket lifecycle
Extensions
- MiddlewareExtension on Middleware
- MiddlewareExtensions on Middleware
- Extensions on Middleware to aid in composing Middleware and Handlers.
- RequestBodyAccessorExtension on Request
- ResponseHandlerToMiddleware on ResponseHandler
- RouterParams on Request
- RouterPlusExtension on Router
- ShelfRequestExtension on Request
Properties
- addChunkedEncoding → Middleware
-
Middleware that adds
chunked transfer coding
to a responses if none of the following conditions are true:
final
Functions
-
addResponseHandler(
List< ResponseHandler> handler) → Middleware -
cascade(
List< Handler> handler) → Handler - Merges multiple Handler into a cascade of handler. Uses the shelf Cascade ruleset.
-
createFileHandler(
String path, {String? url, String? contentType}) → Handler -
Creates a shelf Handler that serves the file at
path
. -
createMiddleware(
{FutureOr< Response?> requestHandler(Request)?, FutureOr<Response> responseHandler(Response)?, FutureOr<Response> errorHandler(Object error, StackTrace)?}) → Middleware - Creates a Middleware using the provided functions.
-
createStaticHandler(
String fileSystemPath, {bool serveFilesOutsidePath = false, String? defaultDocument, bool listDirectories = false, bool useHeaderBytesForContentType = false, MimeTypeResolver? contentTypeResolver}) → Handler -
Creates a Shelf Handler that serves files from the provided
fileSystemPath
. -
download(
{String? filename}) → Middleware - Changes the response headers in a way, browsers will handle the http response as a download.
-
logRequests(
{void logger(String message, bool isError)?}) → Middleware - Middleware which prints the time of the request, the elapsed time for the inner handlers, the response's status code and the request URI.
-
params(
Request request, String name) → String - Get a URL parameter captured by the Router.
-
resolveResponse(
Request request, dynamic result) → Future< Response> -
Resolves a shelf Response from generic
result
based on registered ResponseHandler. -
setContentType(
String mimeType) → Middleware -
Sets the content type header of the response to given
mimeType
. -
shelfRun(
FutureOr< Handler> init(), {int defaultBindPort = 8080, Object defaultBindAddress = 'localhost', bool defaultEnableHotReload = true, SecurityContext? securityContext, OnStarted? onStarted, OnStartFailed? onStartFailed, OnWillClose? onWillClose, OnClosed? onClosed}) → Future<ShelfRunContext> - Mechanism to quickly run a shelf app.
-
typeByExtension(
String fileExtension, {String unknownMimeType = 'application/unknown'}) → Middleware -
Sets the content type header of the response to a mime-type that
matches the give
fileExtension
.
Typedefs
-
Handler
= FutureOr<
Response> Function(Request request) - A function which handles a Request.
- Middleware = Handler Function(Handler innerHandler)
- A function which creates a new Handler by wrapping a Handler.
-
OnClosed
= FutureOr<
void> Function() - OnStarted = void Function(Object address, int port)
- OnStartFailed = void Function(Object e)
-
The type
e
represents the error or exception that occurred. -
OnWillClose
= FutureOr<
void> Function() -
ResponseHandler
= FutureOr<
Object?> Function(Request request, dynamic data) - Model for converting an object into another one.
Exceptions / Errors
- HijackException
- An exception used to indicate that a request has been hijacked.