-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 google.api.HttpBody? #344
Comments
Augmenting this post-conversation for posterity:
ML, per https://code-review.googlesource.com/c/34871. My understanding of this FRGiven a discovery doc like the following: https://ml.googleapis.com/$discovery/rest?version=v1, we should look for things like,
And when we see GoogleApi__HttpBody we should skip the JSON decoding step. We did this in cl34871 but the signal is the specific method name - this request asks us to generalize. |
Sorry, yes, I meant other than the ML APIs. Yeah, I think we need to handle HttpBody for return values, too. CL 34871 is missing a couple things. It ignores ContentType, which are important for the healthcare API, at least - maybe others. It also treats Body's string type as an alias to []byte, which is problematic because of #346, creating an inconsistency with how it's handled in other parts of the surface. Two options (there's probably more):
|
Looks like only For some reason, ML ends up with a type name of GoogleApi__HttpBody, and healthcare as simply HttpBody. ML API has HttpBody as a field in GoogleCloudMlV1__PredictRequest Healthcare API has HttpBody as a function parameter in CreateResource See internal bug 38043930 for more detail on discovery generation problems with HttpBody. |
The following is maybe only for healthcare, since it has so many raw HTTP operations... I'm leaning towards adding a top-level helper to Service:
This would essentially pass through to the underlying http.Client, also prefixing Service.BasePath to the provided path. Then, for any method that asks for (or returns) an HttpBody, document that people should use DoHTTP instead. Other names to bikeshed: |
Should we change the API (make it easier to use than work around it)? I agree this would be OK to do for just Healthcare - not a widespread issue. I'm good with any of the names. I like "HTTP" because it connects with |
Healthcare needs to return |
Figured out a more elegant way to handle this. Please review over on CL 39310. Code looks like this to use: call := fhirService.CreateResource(parent, resourceType, bytes.NewReader(jsonPayload))
call.Header().Set("Content-Type", "application/fhir+json;charset=utf-8")
resp, err := call.Do()
if err != nil {
return fmt.Errorf("CreateResource: %v", err)
}
defer resp.Body.Close() This is quite a bit better than requiring users construct their own *http.Request, because they get type safety on the correct method and URL path parameters via the discovery service. This means you only get access to change the body and any headers. We can add more stuff later if we need to. |
This takes a different approach than the changes made for the ML API (see #241). Healthcare and ML API, strangely, have different formats for HttpBody. They are the only two APIs currently using HttpBody. This change makes any HttpBody call accept an io.Reader, which is used as the HTTP request's Body. Headers can be added using the existing Header() function on the Call. Additional headers and parameters are not added, nor is any processing done on the response. This is quite a bit better than requiring users construct their own *http.Request, because they get type safety on the correct method and URL path parameters via the discovery service. Updates #344. Code looks like this to use: call := fhirService.CreateResource(parent, resourceType, bytes.NewReader(jsonPayload)) call.Header().Set("Content-Type", "application/fhir+json;charset=utf-8") resp, err := call.Do() if err != nil { return fmt.Errorf("CreateResource: %v", err) } defer resp.Body.Close() if resp.StatusCode > 299 { return fmt.Errorf("CreateResource: status %d %s", resp.StatusCode, resp.Status) } respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { return fmt.Errorf("Could not read response: %v", err) } Change-Id: I87cbf7535fbdeacf8cf74ba4ead82ecbd9f187f8 Reviewed-on: https://code-review.googlesource.com/c/google-api-go-client/+/39310 Reviewed-by: kokoro <[email protected]> Reviewed-by: Tyler Bui-Palsulich <[email protected]> Reviewed-by: Jean de Klerk <[email protected]>
@broady It looks like this could be closed, or is there still more work to do here? |
This looks to be solved for the APIs that we cared about. As there has not been much traction on this bug over the three years I think it is good enough to close this for now. We can re-evaluate individual cases should the need arise. |
Looks like this was handled specifically for ML engine in #241 (CL 34871) but maybe not for the general case.
For example, healthcare.Projects.Locations.Datasets.FhirStores.Fhir.CreateResource, which accepts raw JSON.
We currently re-encode the JSON and force a bunch of stuff on the user.
Do we know of any API where HttpBody in a request actually works? If not, I propose we apply the ML engine patch to any outgoing request using the HttpBody type.
/cc @jadekler @noahdietz @jba
The text was updated successfully, but these errors were encountered: