vibe.d beta banner
get vibe.d
0.10.0

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

Function path

Attibute to force a specific URL path.

PathAttribute path (
  string data
) @safe;

This attribute can be applied either to an interface itself, in which case it defines the root path for all methods within it, or on any function, in which case it defines the relative path of this method. Path are always relative, even path on interfaces, as you can see in the example below.

See Also

rootPathFromName for automatic name generation.

Example

@path("/foo")
interface IAPI
{
	@path("info2") string getInfo() @safe;
}

class API : IAPI {
	string getInfo() @safe { return "Hello, World!"; }
}

void test()
@safe {
	import vibe.http.router;
	import vibe.web.rest;

	auto router = new URLRouter;

	// Tie IAPI.getInfo to "GET /root/foo/info2"
	router.registerRestInterface!IAPI(new API(), "/root/");

	// Or just to "GET /foo/info2"
	router.registerRestInterface!IAPI(new API());

	// ...
}
Authors

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

Copyright

© 2012-2017 Sönke Ludwig

License

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