http_handlers
This port's purpose is to develop HTTP servers (REST services or Web applications). It defines a DSL to declare HTTP request handlers.
Adapters implementing this port are in charge of processing HTTP requests through a list of handlers.
Install the Dependency
This module is not meant to be used directly. It is used by HTTP client and HTTP server modules.
HTTP Routing Documentation (TODO)
Filters/callbacks definitions and how they can be combined
Design makes easy to test routing, not only callbacks
Functional approach design (immutability, no side effects)
classDiagram
class HttpServerContext
HttpServerContext: HttpServerRequest request
HttpServerContext: HttpServerResponse response
HttpServerContext: Map attributes
HttpServerContext: Exception exception
HttpServerContext: HttpServerContext next()
class HttpHandler
HttpHandler : Boolean predicate(HttpServerContext)
HttpHandler : HttpServerContext callback(HttpServerContext)
HttpHandler : HttpServerContext process(HttpServerContext)
class OnHandler
class AfterHandler
class FilterHandler
class PathHandler
PathHandler : List handlers
HttpHandler <|-- OnHandler
HttpHandler <|-- AfterHandler
HttpHandler <|-- PathHandler
HttpHandler <|-- FilterHandler
HTTP Context
These are the events that the handlers handle (they are also called HTTP calls or just calls along this documentation). They wrap HTTP requests and responses along with some attributes that may be used to pass data across handlers or to signal that a previous callback resulted in an error.
The HTTP context provides you with everything you need to handle an HTTP request. It contains the request, the response, and a bunch of utility methods to return results, read parameters or pass attributes among handlers.
The methods are available directly from the callback. You can check the API documentation for the full list of methods. This sample code illustrates the usage: