New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vibe.web.web: Allow to return strings #1854

Merged
merged 2 commits into from Apr 3, 2018

Conversation

Projects
None yet
4 participants
@wilzbach
Contributor

wilzbach commented Jul 18, 2017

Split-off from #1697

@wilzbach wilzbach referenced this pull request Jul 18, 2017

Open

[RFC] vibe.web.web: Support JSON more natively #1697

0 of 3 tasks complete
@@ -964,6 +964,8 @@ private void handleRequest(string M, alias overload, C, ERROR...)(HTTPServerRequ
} else {
res.writeBody(ret);
}
} else static if (is(RET : string)) {
res.writeBody(ret);
} else {
static assert(is(RET == void), M~": Only InputStream, Json and void are supported as return types for route methods.");

This comment has been minimized.

@WebFreak001

WebFreak001 Jul 25, 2017

Contributor

Don't forget to include string in the error message

@wilzbach

This comment has been minimized.

Contributor

wilzbach commented Oct 10, 2017

Don't forget to include string in the error message

Thanks. Added!

@wilzbach

This comment has been minimized.

Contributor

wilzbach commented Nov 30, 2017

@s-ludwig anything blocking this? Returning a string happens often enough, s.t. imho it justifies the convenience and also this is just an added bonus as a couple of return types (InputStream and Json are already accepted).

@wilzbach

This comment has been minimized.

Contributor

wilzbach commented Apr 2, 2018

Ping @s-ludwig - I think this is a trivial, non-controversial addition and helps a lot of people as returning string is a frequent use case.

@WebFreak001

This comment has been minimized.

Contributor

WebFreak001 commented Apr 2, 2018

@s-ludwig merge pls, this is really useful and further changes can be done afterwards

@@ -1020,8 +1029,10 @@ private void handleRequest(string M, alias overload, C, ERROR...)(HTTPServerRequ
} else {
res.writeBody(ret);
}
} else static if (is(RET : string)) {

This comment has been minimized.

@s-ludwig

s-ludwig Apr 2, 2018

Member

const(char)[] is sufficient here.

} else {
static assert(is(RET == void), M~": Only InputStream, Json and void are supported as return types for route methods.");
static assert(is(RET == void), M~": Only InputStream, Json, string and void are supported as return types for route methods.");

This comment has been minimized.

@s-ludwig

s-ludwig Apr 2, 2018

Member

Would be nice to add const(ubyte)[] here, too (and change to const(char)[] if adjusted).

@s-ludwig

This comment has been minimized.

Member

s-ludwig commented Apr 2, 2018

Couldn't find a compelling argument against this, especially considering that ubyte[] and char[] are already supported by writeBody in a similar way. Would just be nice to loosen this up to const(char)[] instead of string.

@wilzbach

This comment has been minimized.

Contributor

wilzbach commented Apr 2, 2018

Would just be nice to loosen this up to const(char)[] instead of string.

Good idea. Done.

wilzbach and others added some commits Jul 18, 2017

@s-ludwig s-ludwig added the auto-merge label Apr 2, 2018

@dlang-bot dlang-bot merged commit e42f30b into vibe-d:master Apr 3, 2018

3 checks passed

codecov/patch Coverage not affected when comparing b9985f4...72e9c3b
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment