Skip to content

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

Open
wilzbach wants to merge 1 commit intovibe-d:masterfrom
wilzbach:jsonify-web
Open

[RFC] vibe.web.web: Support JSON more natively#1697
wilzbach wants to merge 1 commit intovibe-d:masterfrom
wilzbach:jsonify-web

Conversation

@wilzbach
Copy link
Copy Markdown
Member

@wilzbach wilzbach commented Feb 27, 2017

A couple of improvement ideas to help working with Json:

@s-ludwig
Copy link
Copy Markdown
Member

The direction definitely makes sense. What I had in mind for quite a while now was to let the REST and web interface generators share more code - maybe in the form of using RestInterface!T also for web interfaces (with a few adjustments). This means that specifying a whole-body JSON parameter in web interfaces would work the same as for RESTful interfaces: @bodyParam("p") void fun(Json p) {}.

One reason for going that route (apart from strengthening the least-surprise factor) is that I recently had a lot of places where having @queryParam and @bodyParam in the web interface would have been really useful.

@wilzbach
Copy link
Copy Markdown
Member Author

The direction definitely makes sense.

As this stalled a bit in the queue, I have split this PR into three pieces which should make it a lot easier to evaluate them in small pieces (I think the split-offs are non-controversial, only this one might be).

This means that specifying a whole-body JSON parameter in web interfaces would work the same as for RESTful interfaces: @bodyParam("p") void fun(Json p) {}.

I agree that this wouldn't be bad, but Json is so commonly nowadays that I would prefer void fun(Json p){} (#1853) or even auto-deserialization from Json: void fun(MyStruct myStruct) (this PR)

@wilzbach
Copy link
Copy Markdown
Member Author

wilzbach commented Apr 2, 2018

This means that specifying a whole-body JSON parameter in web interfaces would work the same as for RESTful interfaces: @bodyParam("p") void fun(Json p) {}.

FYI: this might soon be void fun(@bodyParam Json p){} - the respective language change has already been approved and a working PR is in the queue (dlang/dmd#7576). It just needs a few final tweaks, so if you want to I could with-hold the param changes and make this PR, s.t. it's just about allowing to return a arbitrary type in vibe.web.web which in turn will be serialized to Json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants