-
Notifications
You must be signed in to change notification settings - Fork 9
Support limited form of HTTP service definition #2
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
Comments
Another style for writing the same endpoints above might be like this:
This way if multiple methods are based on the same endpoint, but use different parameters or return different responses, they could all be grouped in a more DRY fashion. |
Hey, Thanks for giving this some thought! There are two high-level approaches that can be taken here:
I'd just like to outline what the second approach would look like for one of your examples: Using options, an existing language concept:
Using rust-like attributes, a general purpose syntax addition for carrying metadata:
Attribute have the benefit of being fairly recognizable for many languages (annotations in Java, attributes in Rust, data annotations in c#, ...) and being compact. Introducing a general purpose way of carrying metadata also means more "bang for the buck". First-class syntax is a bit scarier. They typically occupy a number of keywords which then can't be used for field names, unless we change how the parser works. |
Both of the examples you provide seem very nice to me. It's true that supporting every possible HTTP endpoint is difficult, but supporting a useful subset somehow seems immensely worthwhile to me. It would remove a ton of boilerplate. For example, with a I'm just voicing my support for this feature. Even in the absence of it, |
Considering that any implementation of this concept of services would be highly opinionated, if it gets implemented, it might be worthwhile to include an option in |
Agreed on all counts. Putting it behind a feature flag is a good way to introduce it through experimentation. The existing module system would be suitable for that. |
We now have type-checked attributes: I've also started putting together client-side codegen for okhttp (Java) here: |
This looks awesome! I'm glad to see progress happening here! |
A number of test cases have been added which is working towards getting HTTP support through various frameworks. The code at least in Java and Python has been sufficiently cleaned up with |
Just throwing some ideas out here, but I believe that it would be possible to support a large subset of HTTP endpoints without too much added complexity.
The syntax could probably use some work, but I hope the intention is clear. Each defined endpoint would have a URL, an HTTP method, and a choice between sending the data in the HTTP body as JSON or url-encoding the parameters. If there are no parameters, then url-encoded and json-body would have no effect, so they could be optionally included or left out, but it should be mandatory to specify that when there are parameters.
With the generated Rust code, you would simply call
listByBreed("siamese")
and it would return aResult<Vec<Cat>, Error>
, by retrieving and parsing the response from GETtinghttps://example.com/cats/list?breed=siamese
.For web services where the authentication is part of the request body, this should cover almost any common case. Adding support for Basic Auth could be useful for legacy web services, but I don't think it's a huge concern.
The text was updated successfully, but these errors were encountered: