Skip to content
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

Generate google.api.http-based clients #948

Open
moecasts opened this issue Oct 10, 2023 · 5 comments · May be fixed by #1075
Open

Generate google.api.http-based clients #948

moecasts opened this issue Oct 10, 2023 · 5 comments · May be fixed by #1075

Comments

@moecasts
Copy link

moecasts commented Oct 10, 2023

https://cloud.google.com/endpoints/docs/grpc/transcoding

is possible to generate a http client from a proto like:

syntax = "proto3";

package api.hellp;

service GreeterService {
  rpc Hello(HelloRequest) returns (HelloReply) {
    option (google.api.http) = {
      post: "/hello/{name}",
      body: "*",
    };
  };
}

message HelloRequest {
  string name = 1;
  string sentence = 2;
}

message HelloReply {}

Expect ouput like:

export class HelloServiceClientImpl {
  constructor(http = fetch) {
    this.http = http;
  }

  hello(request: HelloRequest) => {
    const localVarPath = `/v1/dentities/{id}`
    const url = localVarPath.replace('{id}', request.id);

    return this.http({
      url,
      method: 'post',
      data: request,
    })
  }
}
@moecasts moecasts changed the title [FeatureRequest] generate http clinet implementation [FeatureRequest] generate http client implementation Oct 10, 2023
@stephenh
Copy link
Owner

Hi @moecasts , no, I don't think that's possible today... We can generate clients for Twirp, Grpc, Nice rpc, and NestJS, but it looks like you're using the google.api.http extensions, which we don't have any special processing for.

If you'd be interesting in submitting a PR for this support, that'd be great!

You could probably crib from the existing client impls to get going. As a disclaimer I've seen the google.api.http annotations are a thing, but don't really know much about them otherwise.

@stephenh stephenh changed the title [FeatureRequest] generate http client implementation Generate google.api.http-based clients Oct 13, 2023
@erba
Copy link

erba commented Nov 17, 2023

I also have this issue. Spent some hours trying to use the generated code by "ts-proto", from protobufs which all use "google.api.http".
Maybe add into your documentation what protobuf extensions/packages or whatever they are called, are supported.
In the end people just want to transpile protos into ts and start sending their requests. Having to know what protobuf extensions are is a bit much, but that is just my humble opinion.

@stephenh
Copy link
Owner

@erba fwiw I agree the google.api.http extensions are confusing, which frankly is kind of par-of-the-course for the whole protobuf/gRPC ecosystem. 🤷

Personally I've not used them, which is why ts-proto doesn't support them; I'll add a disclaimer to the readme.

Happy to have anyone that wants/needs this submit a PR.

@paralin
Copy link
Collaborator

paralin commented Nov 19, 2023

I have some extensions for timestamp here, could add the other packages like http as well: https://github.com/aperturerobotics/ts-proto-common-types

@erba
Copy link

erba commented Nov 20, 2023

@stephenh Thanks for that. Sorry for the curt tone of the last message. In the end this is not your fault. It seems expecting to use protobuf just like an openapi spec - i.e transpiling it and starting using client code right away - is not realistic.
Protobuf seems to be more complex and needs understanding even from the client code users, which is a pity.

@jas-chen jas-chen linked a pull request Jul 16, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants