grpc-gateway icon indicating copy to clipboard operation
grpc-gateway copied to clipboard

allow request body in GET

Open debankur1 opened this issue 1 year ago • 2 comments

adding request body in GET RPC getting the below error Failure: plugin openapiv2: must not set request body when http method is GET: GetDiagnosis

I am aware of setting allow_delete_body=true in opt, which allows a request body for DELETE , is same can be done with GET?

Though it is not a good practice to send body in GET ,but I have a situation as such.

debankur1 avatar Dec 11 '22 18:12 debankur1

There's no support for setting request bodies in GET requests, my understanding is that the HTTP spec allows them but also that servers should ignore them, so I don't think we're going to allow it. Do you have information you aren't able to pass as path or query parameters?

johanbrandhorst avatar Dec 12 '22 00:12 johanbrandhorst

If you use the fetch API in JS, this will not work and trigger the following error.

Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.

Even if XHR allows that, the RFC says following:

A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.

There are proxies that will definitely break your request in various ways if you include a body on GET. Avoid troubles and don't do it.

veith avatar Dec 26 '22 01:12 veith