vibe.d beta banner
get vibe.d

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.


interface IAPI
	@path("info2") string getInfo() @safe;

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

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

	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());

	// ...

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


© 2012-2017 Sönke Ludwig


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