-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Support combination of query params and body for POSTs with body: "*" #234
Comments
@atombender this would be a great addition, I'm happy to review any work or answer any questions. |
Cool! Naively, would there be any harm in changing the heuristic so that if the |
See https://github.com/googleapis/googleapis/blob/master/google/api/http.proto for semantics. In particular https://github.com/googleapis/googleapis/blob/master/google/api/http.proto#L130 shows that path params should be used for those that aren't provided in body (for '*' case). |
Maybe I'm misunderstanding you, but with I have to admit that the wording in |
I would suggest sending a pull request to googleapis/googleapis to clarify the wording in whichever way is easiest and see what they do. If they accept then implement that, else prefer the other. |
@atombender sorry I misread your original post. On reading further my understanding is that in the context of |
I find the spec confusingly worded. Why are query params singled out? A few paragraphs down:
This doesn't make sense to me. REST-style
In the context of gRPC, I don't see any reason not to map |
@jayantkolhe comments? |
IIUC, the spec by Could you give me some real use cases of this feature? If we have enough number of reasonable use cases, probably we can relax the restriction with a certain explicit configuration, like a command line option of @tmc Thank you for your PR. But I cannot agree on it at this moment. Let's discuss the expected spec here. |
I did give a use case in my original comment. Query parameters are generally more user-friendly than JSON. Let's say I have a big message stored in a file called $ curl -d @data.json http://localhost/ingest Something goes wrong and I want to debug this. Say my service takes a parameter $ curl -d @data.json http://localhost/ingest?verbose=true However, this is not possible. |
@yugui shouldn't path parameters be included but not query string parameters? |
For the use-case Alexander mentions, we have typically recommended using On Wed, Oct 19, 2016 at 11:37 AM, Travis Cline [email protected]
|
Sure, it would be nice if grpc-gateway had a general-purpose mechanism for mapping headers. For a public-facing API it's a bit ridiculous to require users to format a header such as However, headers aren't very ergonomic, since they are generally treated as out-of-band data. It's common for apps to log URLs and query params, for example, but not headers. With headers it's one more thing to consider. |
FWIW I've personally wanted the PUT to /entity/{ID} use case to populate the ID from the path. |
@atombender Thank you for the second example. Based on the example, right, headers are out-of-band. But it looks to be natural in the second example because I'm not strongly against this feature. But I need to understand what we actually need better with good examples because we are trying to go out of the combat-proven design by |
Sure, headers are less ergonomic than query params, but a decent compromise. But grpc-gateway doesn't support a generic mapping of headers, either (that I know of). So you can't argue that headers are better unless you propose that |
Whether we agree with it or not, it seems pretty clear from the proto file that if |
I think this has stalled out. Please feel free to reopen if you have a strong opinion about this and would like to revisit it.. |
What was the consensus on this issue? |
Just to recap, I think the goal of this issue is for the grpc-gateway to support using However, using specific body parameters ( |
@atombender please correct any incorrect information in my previous post. |
Sorry for poping up this issue again but this is a legitimate use case, take this "standard method" (as stated by the google api design guidelines) as an example: service UserService {
rpc CreateUser(CreateUserRequest) returns User {
option (google.api.http) = {
post: "/users",
body: "user"
};
}
}
message CreateUserRequest {
string password = 1;
User user = 2;
}
message User {
string first_name = 1;
string last_name = 2;
} So the
|
This should be supported? Is this not working? |
Sorry for not mentioning that it was a mere comment just to make it clear it’s a legitimate use case. 🙏 |
For http client, it's seems not working. The path will not bind the query params if i use the generated |
Hi, could you provide an example of some code that's not working? Preferably a github repo. I also think we need a new issue, this is very old. |
Hey folks, I have a usecase of having a
Now what I understand is that it is not allowed for me to have a get call with both query param and body. While I define the request in the proto as follows
Is it fine to define like this? But we cannot define with body: "*". As I have read somewhere it is not allowed? |
GET requests with a body are not supported by the HTTP spec, it's not a grpc-gateway limitation. If you want a body, use POST, PATCH or PUT. |
Currently, according to http.proto, it's not possible to combine both query parameters and a body. I don't see any technical reason why this is not possible; manually tweaking the genertaed
.pb.gw.go
with a call toPopulateQueryParameters
seems to confirm that it works fine.For example, assume that every RPC request accepts a parameter
accessToken
. It's convenient to say that the parameter may occur either in the body or in the query. These should be equivalent:and:
However, grpc-gateway only seems to offer the choice between
body: "*"
andbody: "message"
. I'd actually be happy with a compromise that mandatesaccessToken
always be a query-string param, but you can't choose a subset of fields, either.The text was updated successfully, but these errors were encountered: