vibe.d beta banner
get vibe.d

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 = vibe.internal.meta.funcattr.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.


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.


import vibe.http.router;
	import vibe.http.server;

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

	static size_t handler(scope HTTPServerRequest req, scope HTTPServerResponse res)
		return req.headers.length;

	class MyServiceImpl : MyService {
		// the "foo" parameter will receive the number of request headers
		long getHeaderCount(size_t foo)
			return foo;

	void test(URLRouter router)
	@safe {
		router.registerRestInterface(new MyServiceImpl);

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


© 2012-2018 Sönke Ludwig


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