Skip to content

Commit

Permalink
Merge pull request #1010 from Geod24/fix-deprecation-rest
Browse files Browse the repository at this point in the history
Remove deprecation notice for index handling in vibe.web.rest
  • Loading branch information
s-ludwig committed Mar 25, 2015
2 parents ad2f4cb + 6199883 commit d0c9db3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ docs.json
/docs/prettify
/docs/scripts
/docs/styles
__dummy.html

.dub
dub.selections.json
Expand All @@ -22,8 +23,7 @@ dub.selections.json
# Unittest binaries
vibe-d
tests/*/tests
__test__libevent__
__test__libev__
__test__*__

# Examples
examples/app_skeleton/__test__library__
Expand Down
26 changes: 13 additions & 13 deletions source/vibe/web/common.d
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ unittest
* HTTPMethod extracted
* url path extracted
*/
auto extractHTTPMethodAndName(alias Func)()
auto extractHTTPMethodAndName(alias Func, bool indexSpecialCase)()
{
if (!__ctfe)
assert(false);
Expand All @@ -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;
Expand All @@ -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(
Expand All @@ -195,7 +195,7 @@ auto extractHTTPMethodAndName(alias Func)()
udurl.isNull() ? url : udurl.get()
);
}

if (isPropertyGetter!T) {
return udaOverride(HTTPMethod.GET, name);
}
Expand All @@ -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);
}
}
Expand All @@ -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");
Expand Down
43 changes: 18 additions & 25 deletions source/vibe/web/rest.d
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ import std.typetuple : anySatisfy, Filter;
The following table lists the mappings from prefix verb to HTTP verb:
<table>
<tr><th>Prefix</th><th>HTTP verb</th></tr>
<tr><td>get</td><td>GET</td></tr>
<tr><td>query</td><td>GET</td></tr>
<tr><td>set</td><td>PUT</td></tr>
<tr><td>put</td><td>PUT</td></tr>
<tr><td>update</td><td>PATCH</td></tr>
<tr><td>patch</td><td>PATCH</td></tr>
<tr><td>add</td><td>POST</td></tr>
<tr><td>create</td><td>POST</td></tr>
<tr><td>post</td><td>POST</td></tr>
</table>
$(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.
Expand All @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion source/vibe/web/web.d
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit d0c9db3

Please sign in to comment.