Effects
Effect is the main building block of the whole framework. It is just a function that returns a stream of events. Using its generic interface we can define API endpoints, event handlers or middlewares.
Building your own Effect
Marble.js HttpEffect is a more specialized form of Effect for processing HTTP requests. Its responsibility is to map every incoming request to response object.
The Effect above responds to incoming request with "Hello, world!" message. In case of HTTP protocol each incoming request has to be mapped to an object with body, status or headers attributes. If the status code or headers are not defined, then the API by default responds with 200 OK
status and Content-Type: application/json
header.
In order to route our first HttpEffect, we have to define the path and method that the incoming request should be matched to. The simplest implementation of an HTTP API endpoint can look like this.
Let's define a little bit more complex endpoint.
Deprecation warning
HttpRequest
url
method
headers
res (HttpResponse)
HttpResponse
Since Marble.js version 3.0, HttpResponse object is accessible via req.res
attribute of every HttpRequest.
Last updated