import vibe.http.server : HTTPServerRequest, HTTPServerResponse; interface MyService { long getHeaderCount(size_t foo = 0); } size_t handler(HTTPServerRequest req, HTTPServerResponse res) { return req.headers.length; } class MyServiceImpl : MyService { // the "foo" parameter will receive the number of request headers @before!handler("foo") long getHeaderCount(size_t foo) { return foo; } } void test(URLRouter router) { router.registerRestInterface(new MyServiceImpl); }
Allows processing the server request/response before the handler method is called.
Note that this attribute is only used by registerRestInterface, but not by the client generators. This attribute expects the name of a parameter that will receive its return value.
Writing to the response body from within the specified hander function causes any further processing of the request to be skipped. In particular, the route handler method will not be called.
Note: The example shows the drawback of this attribute. It generally is a leaky abstraction that propagates to the base interface. For this reason the use of this attribute is not recommended, unless there is no suitable alternative.