vibe.d beta banner
get vibe.d
0.8.1

Asynchronous I/O that doesn’t get in your way, written in D

Alias before

Allows processing the server request/response before the handler method is called.

alias before ;

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.

Example

import vibe.http.server : HTTPServerRequest, HTTPServerResponse;

interface MyService {
	long getHeaderCount(size_t foo = 0);
}

static 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);
}
Authors

Sönke Ludwig, Михаил Страшун, Mathias 'Geod24' Lang

Copyright

© 2012-2017 RejectedSoftware e.K.

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.