Skip to content
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

JavaScript based REST interface client #1209

Merged
merged 8 commits into from
Sep 13, 2015
Merged

JavaScript based REST interface client #1209

merged 8 commits into from
Sep 13, 2015

Conversation

s-ludwig
Copy link
Member

@s-ludwig s-ludwig commented Aug 3, 2015

No description provided.

@Geod24
Copy link
Contributor

Geod24 commented Aug 3, 2015 via email

@s-ludwig
Copy link
Member Author

s-ludwig commented Aug 4, 2015

I have actually started to work on the duplication issue (which is already present even without this addition), but the current RestInterface struct intended for this is still not ready for CT generation, because it currently requires the RestInterfaceSettings for a lot of things. I'll work on that later.

I'll probably create a 0.7.24 branch during the next couple of days and start merging your remaining changes in vibe.web.rest. Then I'd do a larger refactoring, moving things out of the vibe.web.rest module and switching over to use RestInterface there, too.

@s-ludwig s-ludwig force-pushed the restjsclient branch 3 times, most recently from b454c2c to cc0d0a4 Compare August 5, 2015 05:29
@s-ludwig
Copy link
Member Author

s-ludwig commented Aug 5, 2015

Cleaned up the commit history for review.

@s-ludwig s-ludwig force-pushed the restjsclient branch 3 times, most recently from 61c6209 to b1bc236 Compare August 5, 2015 16:52
header, // req.header[]
attributed, // @before
internal // req.params[]
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, internal is for path attribute, isn't it ? Maybe that'll be a more descriptive name. Also body parameters are not meant to stay JSON forever. On that topic: any way to check the server setting ? It's not a big deal, but if someone disable parseQueryString for example, there's no way to detect it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's for path attributes or any other attributes that are passed using req.params. Since there are valid uses outside of path placeholders, I decided against using that as the name. With the "JSON" comment I just wanted to describe the current state, since I'm not sure yet how to best handle multiple formats in terms of the internal architecture.

Currently there is no way to check the server settings. Really the only possibility that I see would be to throw an exception from inside HTTPServerRequest if the .json field is accessed without the parseJson setting. Another, probably better, path would be to switch the whole JSON body parsing to happen lazily and optionally strongly typed.

@Geod24
Copy link
Contributor

Geod24 commented Aug 6, 2015

Hum, another P.R. blocked by 2.065 :(

Also, it looks like there's a discrepancy between the client and server with the refactoring:

REST route: GET /root/get_check/:param/:param2 []
add route GET /root/get_check/:param/:param2
[...]
no route match: GET /root/getCheck/one/two
No response written for /root/getCheck/one/two
REST call: GET http://127.0.0.1:8000/root/getCheck/one/two -> 404, 404

For the rest, the diff is large, so I'll probably have to try it out on my machine to be sure, but I like where it's heading at. I'm not that familiar with JS, but the new functionality looks cool 👍

@s-ludwig
Copy link
Member Author

s-ludwig commented Aug 7, 2015

Fixed the inconsistency (c5d3208) and 2.065 compilation error (ed739a9).

@s-ludwig s-ludwig changed the title [WIP] JavaScript based REST interface client JavaScript based REST interface client Aug 9, 2015
@s-ludwig
Copy link
Member Author

BTW, for xref purposes, RestInterface also makes things like #662 and #1070 an easy target.

@s-ludwig
Copy link
Member Author

Rebased on master. I've also fixed the handling of optional parameters. Commit ca3def1 needs some re-review, because during rebase it was just a single big conflict with the write-to-headers change. Apart from that, everything except the default service URL comment and the possible merge of ParameterKind and WebParamAttribute.Origin should be addressed.

I'll have a look at the latter now. Regarding the URL, I don't remember exactly anymore, but I think I got some internal assertions due to an empty service URL, which was quite unobvious for the user. We could alternatively use something like "http://localhost/" or just add high-level assertions with a proper error message. The latter sounds like the better way to go...

@s-ludwig
Copy link
Member Author

@Geod24, did you see any remaining issues? Otherwise I'd rebase/squash and merge now.

@Geod24
Copy link
Contributor

Geod24 commented Sep 11, 2015

I'll do a last sweep this evening ;)

@Geod24
Copy link
Contributor

Geod24 commented Sep 11, 2015

Can't see anything.
All your project build out of the box with the new version ?

@s-ludwig
Copy link
Member Author

I haven't tested all of them yet, but I'll do that now.

@s-ludwig s-ludwig force-pushed the restjsclient branch 2 times, most recently from 6997c4c to eebf993 Compare September 13, 2015 07:44
s-ludwig added a commit that referenced this pull request Sep 13, 2015
@s-ludwig
Copy link
Member Author

Okay, when testing my projects I found one bug in the REST client (09ee6a2), but none in the new code. Will merge once Travis goes green.

s-ludwig added a commit that referenced this pull request Sep 13, 2015
JavaScript based REST interface client
@s-ludwig s-ludwig merged commit 897521b into master Sep 13, 2015
@s-ludwig
Copy link
Member Author

And thanks for reviewing this lengthy change set!

@s-ludwig s-ludwig deleted the restjsclient branch September 13, 2015 09:40
@etcimon
Copy link
Contributor

etcimon commented Sep 13, 2015

I would have loved to review this but got caught up in the busiest time of the past few years. Sorry!

// XHR setup
output.put(" var xhr = new XMLHttpRequest();\n");
output.formattedWrite(" xhr.open('%s', url, true);\n", route.method.to!string.toUpper);
static if (!is(RT == void)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for not catching this sooner, but is RT actually defined here? I think it's causing this block to execute regardless of return type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks like that... is() and __traits(compiles) are really suboptimal constructs w.r.t. correctness. I'll add a test and fix this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Err.. or rather just merge your PR and add a test ;)

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.

4 participants