From 1773fbc1a839f5b4b751d357fab577de768aa31b Mon Sep 17 00:00:00 2001 From: Geod24 Date: Wed, 25 Mar 2015 21:18:57 +0100 Subject: [PATCH 1/2] Update documentation --- .gitignore | 4 ++-- source/vibe/web/rest.d | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 10a5920283..74650eea81 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ docs.json /docs/prettify /docs/scripts /docs/styles +__dummy.html .dub dub.selections.json @@ -22,8 +23,7 @@ dub.selections.json # Unittest binaries vibe-d tests/*/tests -__test__libevent__ -__test__libev__ +__test__*__ # Examples examples/app_skeleton/__test__library__ diff --git a/source/vibe/web/rest.d b/source/vibe/web/rest.d index b4205f0e76..a895c80931 100644 --- a/source/vibe/web/rest.d +++ b/source/vibe/web/rest.d @@ -32,22 +32,22 @@ import std.typetuple : anySatisfy, Filter; The following table lists the mappings from prefix verb to HTTP verb: - - - - - - - - - - - -
PrefixHTTP verb
getGET
queryGET
setPUT
putPUT
updatePATCH
patchPATCH
addPOST
createPOST
postPOST
+ $(TABLE + $(TR $(TH Prefix) $(TH HTTP verb)) + $(TR $(TD get) $(TD GET)) + $(TR $(TD query) $(TD GET)) + $(TR $(TD set) $(TD PUT)) + $(TR $(TD put) $(TD PUT)) + $(TR $(TD update) $(TD PATCH)) + $(TR $(TD patch) $(TD PATCH)) + $(TR $(TD add) $(TD POST)) + $(TR $(TD create) $(TD POST)) + $(TR $(TD post) $(TD POST)) + ) If a method has its first parameter named 'id', it will be mapped to ':id/method' and - 'id' is expected to be part of the URL instead of a JSON request. Parameters with default - values will be optional in the corresponding JSON request. + 'id' is expected to be part of the URL instead of a JSON request. Parameters with default + values will be optional in the corresponding JSON request. Any interface that you return from a getter will be made available with the base url and its name appended. @@ -58,7 +58,7 @@ import std.typetuple : anySatisfy, Filter; must either be an interface type, or a class which derives from a single interface settings = Additional settings, such as the $(D MethodStyle), or the prefix. - See $(D RestInterfaceSettings) for more details. + See $(D RestInterfaceSettings) for more details. See_Also: $(D RestInterfaceClient) class for a seamless way to access such a generated API From 61998837796e0a2df42849b0d56a9dbc2be6c616 Mon Sep 17 00:00:00 2001 From: Geod24 Date: Wed, 25 Mar 2015 23:24:36 +0100 Subject: [PATCH 2/2] Remove special handling of 'index' in vibe.web.rest --- source/vibe/web/common.d | 26 +++++++++++++------------- source/vibe/web/rest.d | 13 +++---------- source/vibe/web/web.d | 2 +- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/source/vibe/web/common.d b/source/vibe/web/common.d index 16f66d3327..c93a33dbba 100644 --- a/source/vibe/web/common.d +++ b/source/vibe/web/common.d @@ -137,7 +137,7 @@ unittest * HTTPMethod extracted * url path extracted */ -auto extractHTTPMethodAndName(alias Func)() +auto extractHTTPMethodAndName(alias Func, bool indexSpecialCase)() { if (!__ctfe) assert(false); @@ -162,8 +162,8 @@ auto extractHTTPMethodAndName(alias Func)() HTTPMethod.POST : [ "add", "create", "post" ], HTTPMethod.DELETE : [ "remove", "erase", "delete" ], ]; - - string name = __traits(identifier, Func); + + enum name = __traits(identifier, Func); alias T = typeof(&Func) ; Nullable!HTTPMethod udmethod; @@ -186,7 +186,7 @@ auto extractHTTPMethodAndName(alias Func)() if (!udmethod.isNull() && !udurl.isNull()) { return HandlerMeta(true, udmethod.get(), udurl.get()); } - + // Anti-copy-paste delegate typeof(return) udaOverride( HTTPMethod method, string url ){ return HandlerMeta( @@ -195,7 +195,7 @@ auto extractHTTPMethodAndName(alias Func)() udurl.isNull() ? url : udurl.get() ); } - + if (isPropertyGetter!T) { return udaOverride(HTTPMethod.GET, name); } @@ -211,10 +211,10 @@ auto extractHTTPMethodAndName(alias Func)() } } } - - if (name == "index") + + static if (indexSpecialCase && name == "index") { return udaOverride(HTTPMethod.GET, ""); - else + } else return udaOverride(HTTPMethod.POST, name); } } @@ -236,23 +236,23 @@ unittest string mattersnot(); } - enum ret1 = extractHTTPMethodAndName!(Sample.getInfo); + enum ret1 = extractHTTPMethodAndName!(Sample.getInfo, false,); static assert (ret1.hadPathUDA == false); static assert (ret1.method == HTTPMethod.GET); static assert (ret1.url == "Info"); - enum ret2 = extractHTTPMethodAndName!(Sample.updateDescription); + enum ret2 = extractHTTPMethodAndName!(Sample.updateDescription, false); static assert (ret2.hadPathUDA == false); static assert (ret2.method == HTTPMethod.PATCH); static assert (ret2.url == "Description"); - enum ret3 = extractHTTPMethodAndName!(Sample.putInfo); + enum ret3 = extractHTTPMethodAndName!(Sample.putInfo, false); static assert (ret3.hadPathUDA == false); static assert (ret3.method == HTTPMethod.DELETE); static assert (ret3.url == "Info"); - enum ret4 = extractHTTPMethodAndName!(Sample.getMattersnot); + enum ret4 = extractHTTPMethodAndName!(Sample.getMattersnot, false); static assert (ret4.hadPathUDA == true); static assert (ret4.method == HTTPMethod.GET); static assert (ret4.url == "matters"); - enum ret5 = extractHTTPMethodAndName!(Sample.mattersnot); + enum ret5 = extractHTTPMethodAndName!(Sample.mattersnot, false); static assert (ret5.hadPathUDA == true); static assert (ret5.method == HTTPMethod.POST); static assert (ret5.url == "compound/path"); diff --git a/source/vibe/web/rest.d b/source/vibe/web/rest.d index a895c80931..9914597cd9 100644 --- a/source/vibe/web/rest.d +++ b/source/vibe/web/rest.d @@ -112,19 +112,12 @@ void registerRestInterface(TImpl)(URLRouter router, TImpl instance, RestInterfac foreach (method; __traits(allMembers, I)) { foreach (overload; MemberFunctionsTuple!(I, method)) { - enum meta = extractHTTPMethodAndName!overload(); + enum meta = extractHTTPMethodAndName!(overload, false)(); static if (meta.hadPathUDA) { string url = meta.url; } else { - static if (__traits(identifier, overload) == "index") { - pragma(msg, "Processing interface " ~ I.stringof ~ - ": please use @path(\"/\") to define '/' path" ~ - " instead of 'index' method. Special behavior will be removed" ~ - " in the next release."); - } - string url = adjustMethodStyle(strip(meta.url), settings.methodStyle); } @@ -817,7 +810,7 @@ private string generateRestInterfaceSubInterfaceInstances(I)() tps ~= RT.stringof; string implname = RT.stringof ~ "Impl"; - enum meta = extractHTTPMethodAndName!overload(); + enum meta = extractHTTPMethodAndName!(overload, false)(); ret ~= q{ auto settings_%1$s = m_settings.dup; @@ -922,7 +915,7 @@ private string genClientBody(alias Func)() { alias PTT = ParameterTypeTuple!Func; alias ParamNames = ParameterIdentifierTuple!Func; - enum meta = extractHTTPMethodAndName!Func(); + enum meta = extractHTTPMethodAndName!(Func, false)(); enum paramAttr = UDATuple!(WebParamAttribute, Func); enum FuncId = __traits(identifier, Func); diff --git a/source/vibe/web/web.d b/source/vibe/web/web.d index 02a2b81c97..7652fac1e7 100644 --- a/source/vibe/web/web.d +++ b/source/vibe/web/web.d @@ -127,7 +127,7 @@ void registerWebInterface(C : Object, MethodStyle method_style = MethodStyle.low static if (!is(typeof(__traits(getMember, Object, M)))) { // exclude Object's default methods and field foreach (overload; MemberFunctionsTuple!(C, M)) { alias RT = ReturnType!overload; - enum minfo = extractHTTPMethodAndName!overload(); + enum minfo = extractHTTPMethodAndName!(overload, true)(); enum url = minfo.hadPathUDA ? minfo.url : adjustMethodStyle(minfo.url, method_style); static if (is(RT == class) || is(RT == interface)) {