gleam/http/middleware
Types
pub type Middleware( before_req, before_resp, after_req, after_resp, ) = fn(Service(before_req, before_resp)) -> Service(after_req, after_resp)
Functions
pub fn map_resp_body( service: fn(Request(a)) -> Response(b), with mapper: fn(b) -> c, ) -> fn(Request(a)) -> Response(c)
A middleware that transform the response body returned by the service using a given function.
pub fn method_override( service: fn(Request(a)) -> Response(b), ) -> fn(Request(a)) -> Response(b)
A middleware that overrides an incoming POST request with a method given in
the request's _method
query paramerter. This is useful as web browsers
typically only support GET and POST requests, but our application may
expect other HTTP methods that are more semantically correct.
The methods PUT, PATCH, and DELETE are accepted for overriding, all others are ignored.
The _method
query paramerter can be specified in a HTML form like so:
<form method="POST" action="/item/1?_method=DELETE">
<button type="submit">Delete item</button>
</form>
pub fn prepend_resp_header( service: fn(Request(a)) -> Response(b), key: String, value: String, ) -> fn(Request(a)) -> Response(b)
A middleware that prepends a header to the request.