-
Notifications
You must be signed in to change notification settings - Fork 51
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
Handle rendering of URL Query Parameters in renderURL #9
Comments
ah, right it doesn't do that for the moment. How often do you run into this use case? We mostly just leave the Are you putting your hand up to implement this feature? Do you have a rough idea in mind? |
Ah I see. I run into this use-case quite often especially with a GET endpoint like this It would be awesome if the plugin can take care of injecting the URL query parameters otherwise I may have to think of an alternate implementation for a GET endpoint like this I do have a rough idea in mind but that would require modifying the If we do that, then we can create a Please let me know what you think of this idea 🙏🏼 |
I think there are three things that I can think of for you to consider, @atreya2011.
|
Thank you for your feedback and comments 🙇🏼 I will take all of them into consideration when I finalize my PR.
Basically I am trying to following the design convention according to the following comments mentioned in http.proto
However, as you mentioned, the length of the URL needs to considered, so I was thinking that maybe we can support only Please let me know what you think about this idea 🙇🏼
We can perhaps try building the URL Query Parameters like this static ListUsers(req: ListUsersRequest, initReq?: fm.InitReq): Promise<ListUsersResponse> {
return fm.fetchReq<ListUsersRequest, ListUsersResponse>(`/api/v1/users` + new URLSearchParams(req), {...initReq, method: "GET"})
} |
message type and nested types are important. and logically when you start the implementation the request message itself is a message already. might as well take the chance to handle nested types to have a rather complete solution. Sure you need to care about the length of the url, but also the following simple case doesn't really blow up the length of URL too. // ...
message Request {
Payload payload.= 1;
int32 status = 2
}
message Payload {
string fieldA;
string fieldB;
}
// ... static ListUsers(req: ListUsersRequest, initReq?: fm.InitReq): Promise<ListUsersResponse> {
return fm.fetchReq<ListUsersRequest, ListUsersResponse>(`/api/v1/users` + new URLSearchParams(req), {...initReq, method: "GET"})
} using
You might need to write a custom handler somehow. |
I agree regarding the disadvantages of using
Handling of nested fields for a simple case as above is possible and the URL length won't be too long as you have mentioned. Let me try custom handler implementation which renders nested messages as well and check how long the URL gets in case of deep nesting 🙇🏼 Thank you for your comments and feedback 🙏🏼 |
Well, if a user feed a long array in the repeated field then the URL could blow up, or a long text in a single string field could too. Hence why URL is a concern, but it's not against the nested type requirement. We can't control how much user put in the request object. However, we could have optimal URL generation, like how we ditch Well, give it a try and let me know how it goes. Thanks for taking this on. |
Thank you for letting me working on this 🙇🏼 When you get the time, can you let me know if I am going in the right direction in my draft PR. |
The following is extracted from this file: http.proto
However it seems like
renderURL
function inprotoc-gen-grpc-gateway
doesn't render the fields in the request message which are not bound by the path template to become URL query parameters if there is no HTTP request body.Any advice on how to handle this would be great! Thanks in advance 🙏🏼
The text was updated successfully, but these errors were encountered: