woomera library

This is the library that is normally imported when using Woomera. It exports both the core library and the annotations library.

Note: this library no longer exports the (now deprecated) scan library. If legacy code requires the scan library, it must be explicitly imported.

Usage

To create a Web server (a program that listens for HTTP requests and produces HTTP responses), create a Server object and invoke its run method.

final ws = Server();
...
await server.run();

The server only listens for requests on port 80 of the IPv4 loopback address (i.e. 127.0.0.1). This can be changed by properties on the Server object.

final ws = Server()
  ..bindAddress = InternetAddress.anyIPv6
  ..bindPort = 8080;

The server should be assigned one or more ServerPipeline objects Annotate requests handlers and exception handlers using instances of the Handles class (which is defined in the core library).

import 'package:woomera/woomera.dart';

@Handles.get('~/')
Future<Response> homePage(Request req) async {
  final resp = ResponseBuffered(ContentType.html)..write('''
<!DOCTYPE html>
<head>
  <title>Example</title>
</head>
<html>
  <body>
  <p>Hello world!</p>
  </body>
</html>
''');
  return resp;
}

Then create a Server using the serverFromAnnotations function, which will automatically populate the server using the Handles annotations. Then run the server.

Future main() async {
  final server = serverFromAnnotations()
    ..bindAddress = InternetAddress.anyIPv6
    ..v6Only = false // false = listen to any IPv4 and any IPv6 address
    ..bindPort = port;

  await server.run();
}

Classes

Handles
Annotation for a request handler.
HEsc
Escaping arbitrary values for use in HTML documents.
Pattern
Pattern that is used to match a path.
PipelineExceptionHandler
Annotation for a pipeline exception handler function.
Proxy
Proxy for handling requests to another server.
Request
Request class.
RequestHandlerWrapper
Annotation for a request handler wrapper function.
RequestParams
Represents a collection of parameters.
RequestParamsMutable
A mutable RequestParams.
Response
Abstract base class for a response.
ResponseBuffered
A response where the contents is buffered text.
ResponseNoContent
HTTP response has no response body.
ResponseRedirect
HTTP response that redirects the browser to a URL.
ResponseStream
A response where the contents come from a stream.
Server
A Web server.
ServerExceptionHandler
Annotation for a server exception handler function.
ServerExceptionHandlerRaw
Annotation for a server raw exception handler function.
ServerPipeline
A pipeline.
ServerRule
Represents a rule for processing HTTP requests.
Session
Session that is maintained between HTTP requests.
SimulatedHttpConnectionInfo
Simulated HTTP connection information.
SimulatedHttpHeaders
Headers in a simulated request or response
SimulatedResponse
Response returned by simulations.
StaticFiles
Handler for returning static files and directory listings.
WoomeraAnnotation
Abstract base class for all Woomera annotation classes.

Enums

ParamsMode
Modes for processing parameter values.
SessionTermination
Reasons why a session was terminated.
SimulatedResponseBodyType
The source format for the body in a simulated response.

Properties

loggers List<Logger>
List of all the loggers used by this library.
final

Functions

debugHandler(Request req) Future<Response>
Request handler which shows out the request parameters to the client.

Typedefs

ExceptionHandler = Future<Response> Function(Request request, Object exception, StackTrace stackTrace)
Exception handler for high-level situations.
ExceptionHandlerRaw = Future<void> Function(HttpRequest rawRequest, String requestId, Object exception, StackTrace stackTrace)
Exception handler for low-level situations.
HandlerWrapper = RequestHandler Function(Handles rego, Object obj)
Function type for handler wrapper.
RequestCreator = FutureOr<Request> Function(HttpRequest request, String id, Server server)
Type for a request factory.
RequestHandler = Future<Response> Function(Request req)
HTTP request handler function type.

Exceptions / Errors

DuplicateRule
Attempt to register a duplicate rule in a pipeline.
ExceptionHandlerException
Exception indicating an exception/error occurred in an exception handler.
MalformedPathException
Exception indicating malformed request.
NoResponseFromHandler
Exception to indicate a RequestHandler did not produce a response.
NoResponseProduced
Indicates a handler cannot produce a response.
NotFoundException
Exception indicating a response could not be created.
PathTooLongException
Exception indicating the URL path is too large.
PostTooLongException
Exception indicating the contents of the POST request is too large.
ProxyHandlerException
Exception indicating an exception/error occurred in the proxy handler.
WoomeraException
Base class for all exceptions defined in the Woomera package.