-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add default HTTP routes for non-annotated methods #123
Comments
Hey @anhnmt, default bindings aren't provided yet but it's something we would be interested in adding. On registration of an endpoint like: service UserService {
rpc List(ListRequest) returns (ListResponse) {
option (google.api.http) = {get: "/v1/users/{page=*}"};
}
} We should create an additional endpoint with the effective syntax: option (google.api.http) = {
post: "/user.v1.UserService/List"
body: "*"
}; Edit: currently to call your API you would need to use the REST syntax: curl http://localhost:8080/v1/users/1?page_size=10 |
@emcfarlane thank u I tried your method and it worked, but I would have to fix a lot of other methods to get the same result. I wonder if there is any way to optimize this workload, maybe without having to interfere with the .proto file? rpc List(ListRequest) returns (ListResponse) {
option (google.api.http) = {
get: "/v1/users/{page=*}"
additional_bindings {
post: "/user.v1.UserService/List"
body: "*"
}
};
} |
Yes, we plan to add bindings for the default service method similar to https://cloud.google.com/endpoints/docs/grpc/transcoding#where_to_configure_transcoding |
@emcfarlane Hopefully this feature will be released soon |
@anhnmt, how are you actually using Vanguard? This default mapping doesn't seem to provide any value over just using the Connect protocol. So with no annotations in the proto files you could do this:
The only difference between that, and explicitly configuring the service with the annotation (and not including the So do you actually need the "RESTful" format? Or would simply using the Connect protocol suffice? |
Hi @jhump, I'm developing an api gateway that uses vanguard to bridge to my back-end services. My client will call this API like: In addition to the RESTful api, it also supports connecting to services using gPRC as well as the path on Until recently, I wanted to upload files through this gateway and encountered the curl --location 'localhost:8080/user.v1.UserService/Upload' \
--header 'Connect-Protocol-Version: 1' \
--header 'Content-Type: application/json' \
--form 'file=@"/C:/Users/anhnmt/Downloads/build.zip"' My current way is to use an option as follows rpc Upload(UploadRequest) returns (google.protobuf.Empty) {
options (google.api.http) = {
post: "/user.v1.UserService/Upload"
body: "file"
};
}
message UploadRequest {
// The file contents to upload.
google.api.HttpBody file = 1;
} I wonder if you have a better way? |
Since your annotation uses Prior to your latest comment, the example cURL commands and discussion appear to just be ad-hoc usage of some of the API endpoints that were unary JSON, in which case the Connect protocol would work just as well. Your prior example showed having to add a route for |
@jhump Sorry for causing misunderstanding. We use the main route My model looks like: However, my old system doesn't work well and is unstable. Recently I wanted to add some more features including file uploads to the system, we rebuilt it and tried to change as little as possible. |
I have the following program: https://github.com/anhnmt/gprc-dynamic-proto/blob/main/cmd/service/main.go
I have successfully connected grpc and restapi, can I call the api like the following?
I tried and the result was: Not Found
The text was updated successfully, but these errors were encountered: