diff --git a/source/vibe/web/rest.d b/source/vibe/web/rest.d index 287b4f0db6..4c45d3f3da 100644 --- a/source/vibe/web/rest.d +++ b/source/vibe/web/rest.d @@ -61,7 +61,7 @@ import std.traits; $(D RestInterfaceClient) class for a seamless way to access such a generated API */ -void registerRestInterface(TImpl)(URLRouter router, TImpl instance, RestInterfaceSettings settings = null) +URLRouter registerRestInterface(TImpl)(URLRouter router, TImpl instance, RestInterfaceSettings settings = null) { import std.traits : InterfacesTuple; import vibe.internal.meta.uda : findFirstUDA; @@ -154,23 +154,24 @@ void registerRestInterface(TImpl)(URLRouter router, TImpl instance, RestInterfac } } } + return router; } /// ditto -void registerRestInterface(TImpl)(URLRouter router, TImpl instance, MethodStyle style) +URLRouter registerRestInterface(TImpl)(URLRouter router, TImpl instance, MethodStyle style) { - registerRestInterface(router, instance, "/", style); + return registerRestInterface(router, instance, "/", style); } /// ditto -void registerRestInterface(TImpl)(URLRouter router, TImpl instance, string url_prefix, +URLRouter registerRestInterface(TImpl)(URLRouter router, TImpl instance, string url_prefix, MethodStyle style = MethodStyle.lowerUnderscored) { auto settings = new RestInterfaceSettings; if (!url_prefix.startsWith("/")) url_prefix = "/"~url_prefix; settings.baseURL = URL("http://127.0.0.1"~url_prefix); settings.methodStyle = style; - registerRestInterface(router, instance, settings); + return registerRestInterface(router, instance, settings); } @@ -240,8 +241,8 @@ unittest { import vibe.http.server, vibe.http.router; - auto router = new URLRouter(); - registerRestInterface(router, new API()); + auto router = new URLRouter; + router.registerRestInterface(new API()); listenHTTP(new HTTPServerSettings(), router); } } diff --git a/source/vibe/web/web.d b/source/vibe/web/web.d index d512e90054..c8957eeef7 100644 --- a/source/vibe/web/web.d +++ b/source/vibe/web/web.d @@ -130,7 +130,7 @@ import vibe.http.websockets; $(D @vibe.web.common.contentType) The `@path` attribute can also be applied to the class itself, in which - case it will be used as an additional prefix to the one in + case it will be used as an additional prefix to the one in `WebInterfaceSettings.urlPrefix`. Params: @@ -138,7 +138,7 @@ import vibe.http.websockets; instance = Class instance to use for the web interface mapping settings = Optional parameter to customize the mapping process */ -void registerWebInterface(C : Object, MethodStyle method_style = MethodStyle.lowerUnderscored)(URLRouter router, C instance, WebInterfaceSettings settings = null) +URLRouter registerWebInterface(C : Object, MethodStyle method_style = MethodStyle.lowerUnderscored)(URLRouter router, C instance, WebInterfaceSettings settings = null) { import std.algorithm : endsWith; import std.traits; @@ -194,6 +194,7 @@ void registerWebInterface(C : Object, MethodStyle method_style = MethodStyle.low } } } + return router; }