Giter Site home page Giter Site logo

grpc-gateway-example's Introduction

gRPC + REST Gateway Play

Blog post: https://coreos.com/blog/gRPC-protobufs-swagger.html

To try it all out do this:

$ go get -u github.com/philips/grpc-gateway-example
$ grpc-gateway-example serve
$ grpc-gateway-example echo "my first rpc echo"
$ curl -X POST -k https://localhost:10000/v1/echo -H "Content-Type: text/plain" -d '{"value": "foo"}'
{"value":"my REST echo"}

Huge thanks to the hard work people have put into the Go gRPC bindings and gRPC to JSON Gateway

grpc-gateway-example's People

Contributors

graphaelli avatar gregzuro avatar philips avatar samuelvarley avatar sgarciapdx avatar tmc avatar xiang90 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grpc-gateway-example's Issues

An error occurs during execution.

$ go get -u github.com/philips/grpc-gateway-example

cd /root/go/src/github.com/grpc-ecosystem/grpc-gateway; git pull --ff-only
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

git branch --set-upstream-to=origin/<branch> v1.4.1

package github.com/grpc-ecosystem/grpc-gateway/runtime: exit status 1
cd /root/go/src/github.com/golang/protobuf; git pull --ff-only
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

git pull

If you wish to set tracking information for this branch you can do so with:

git branch --set-upstream-to=origin/ v1.2.0

package github.com/golang/protobuf/proto: exit status 1

what is that?

bad practice on creating the tls credentials

on cmd/serve.go: (line 84)
https://github.com/philips/grpc-gateway-example/blob/master/cmd/serve.go#L84
dcreds := credentials.NewTLS(&tls.Config{ ServerName: demoAddr, RootCAs: demoCertPool, })
demoAddr is used for creating the credentials. demoAddr is an endpoint with address:port format. Using that will cause your TLS to look for a serverName of "localhost:10000". Hence, in your certificate, you had to add the domain:port specifically as a server name. It is not good practice to use a specific name in your cert. The ServerName should be only the Address.

fails to start properly

just did a new go get of the code.

I cant start it properly:

go get github.com/philips/grpc-gateway-example
x-MacBook-Pro:philips apple$ code .
x-MacBook-Pro:philips apple$ grpc-gateway-example serve
grpc on port: 10000
2016/05/26 18:56:15 grpc: Conn.resetTransport failed to create client transport: connection error: desc = "transport: dial tcp [::1]:10000: getsockopt: connection refused"; Reconnecting to "localhost:10000"

any ideas ??

x-MacBook-Pro:philips apple$ go version
go version go1.6.2 darwin/amd64

http scheme in service.swagger.json

@philips I did take a closer look at your interesting grpc-gateway-examples code after reading the blog post and noticed some minor problems. I hope you don't mind if I open some issues even though this is "only" example code. Maybe other readers will find this useful.

The echopb/Makefile generates a service.swagger.json with

"schemes": [
    "http",
    "https"
  ],

I've added this line to the Makefile to remove the http scheme.

jq 'del(.schemes[] | select(. == "http"))' service.swagger.json >service.swagger.json.new && mv service.swagger.json.new service.swagger.json

Unfortunately, there's no protoc-gen-swagger option to do this directly.
See: grpc-ecosystem/grpc-gateway#161

go get fails

Hi! I was reading your Take a REST with HTTP/2, Protobufs, and Swagger article and ran the following to try out the example myself:

$ go get -u github.com/philips/grpc-gateway-example

However it fails with the following errors.

$ go get -u github.com/philips/grpc-gateway-example
# github.com/philips/grpc-gateway-example/echopb
echopb/service.pb.gw.go:90: not enough arguments in call to runtime.HTTPError
echopb/service.pb.gw.go:94: not enough arguments in call to forward_EchoService_Echo_0

My guess is that the dependencies APIs have changed since you wrote the example?

transport: http2Client.notifyError got notified that the client transport was broken unexpected EOF.

I just cloned and compiled this project, then ran: ./grpc-gateway-example serve; and got flooded with these messages:

2016/08/11 16:35:16 grpc: addrConn.resetTransport failed to create client transport: connection error: desc = "transport: dial tcp 127.0.0.1:10000: getsockopt: connection refused"; Reconnecting to {"localhost:10000" <nil>}
2016/08/11 16:35:16 transport: http2Client.notifyError got notified that the client transport was broken unexpected EOF.
2016/08/11 16:35:16 transport: http2Client.notifyError got notified that the client transport was broken unexpected EOF.
2016/08/11 16:35:16 transport: http2Client.notifyError got notified that the client transport was broken unexpected EOF.
2016/08/11 16:35:16 transport: http2Client.notifyError got notified that the client transport was broken unexpected EOF.

Go version: 1.7rc6

architectural question: Can i generate the JS client proxy code ?

I am using react web and react native.
One of the big things about React native is that you can update the app, without going through the long wait in the app stores.

SO, i am wondering if there is a way or approach where i can generate the JS client proxy code that talks to the GRPC Gateway.

Or am i taking the wrong approach maybe ?

use of internal package not allowed

Hi @philips Trying to test your example, I have this message.

$ go get -u github.com/philips/grpc-gateway-example

I get:

package github.com/philips/grpc-gateway-example
    imports github.com/philips/grpc-gateway-example/cmd
    imports github.com/gengo/grpc-gateway/runtime
    imports github.com/grpc-ecosystem/grpc-gateway/runtime/internal: use of internal package not allowed
go version go1.6 darwin/amd64

GOPATH="/Users/mypc/workspace/go"

GOBIN="/Users/mypc/workspace/go/bin"

Then with

grpc-gateway-example serve

2016/07/25 13:35:09 grpc: addrConn.resetTransport failed to create client transport: connection error: desc = "transport: dial tcp [::1]:9090: getsockopt: connection refused"; Reconnecting to {"localhost:9090" <nil>}
2016/07/25 13:35:11 grpc: addrConn.resetTransport failed to create client transport: connection error: desc = "transport: dial tcp [::1]:9090: getsockopt: connection refused"; Reconnecting to {"localhost:9090" <nil>}

Did you tried postman or other http client instead of curl?

Hi @philips , I ran the code in my machine, when using curl to send request it's fine

curl -X POST -k https://localhost:10000/v1/echo -H "Content-Type: text/plain" -d '{"value": "foo"}'
{"value":"my REST echo"}

But when I tried the same call with postman it's doing nothing. What could be the possible reason?

Error in server:

2019/02/22 23:52:20 http: TLS handshake error from [::1]:52288: EOF

Incorrect Link for the Article in the Readme

I stumbled across this Github repository and I wanted to read the article. But whenever I click on the link, it redirects to this URL. Can someone mention the article's link if that has been shifted to a new location?

Possible http.Server without TLSConfig?

Is it possible to have an http.Server without a TLSConfig?

diff --git a/cmd/serve.go b/cmd/serve.go
index bb78f80..9e3ff1a 100644
--- a/cmd/serve.go
+++ b/cmd/serve.go
@@ -110,13 +110,13 @@ func serve() {
        srv := &http.Server{
                Addr:    demoAddr,
                Handler: grpcHandlerFunc(grpcServer, mux),
-               TLSConfig: &tls.Config{
-                       Certificates: []tls.Certificate{*demoKeyPair},
-               },
+       }
+       tlsConfig := &tls.Config{
+               Certificates: []tls.Certificate{*demoKeyPair},
        }

        fmt.Printf("grpc on port: %d\n", port)
-       err = srv.Serve(tls.NewListener(conn, srv.TLSConfig))
+       err = srv.Serve(tls.NewListener(conn, tlsConfig))

        if err != nil {
                log.Fatal("ListenAndServe: ", err)
$ go run main.go serve
grpc on port: 10000
2016/07/15 11:53:13 transport: http2Client.notifyError got notified that the client transport was broken unexpected EOF.
2016/07/15 11:53:13 transport: http2Client.notifyError got notified that the client transport was broken unexpected EOF.
2016/07/15 11:53:14 grpc: addrConn.resetTransport failed to create client transport: connection error: desc = "transport: write tcp [::1]:33442->[::1]:10000: write: connection reset by peer"; Reconnecting to {"localhost:10000" <nil>}
2016/07/15 11:53:14 transport: http2Client.notifyError got notified that the client transport was broken unexpected EOF.
2016/07/15 11:53:14 transport: http2Client.notifyError got notified that the client transport was broken unexpected EOF.
2016/07/15 11:53:14 transport: http2Client.notifyError got notified that the client transport was broken unexpected EOF.

See soheilhy/cmux#33 (comment) for context.

swagger-ui issues

@philips The 3rd-party swagger-ui distribution in third_party/swagger-ui/ has some issues:

  1. It is incomplete and references css/print.css and favicon files in index.html that don't exist (in the local copy - upstream they do exist).
  2. The html page in index.html is repeated twice (almost identical): Once with unix LF and once with windows CR+LF.
  3. The file third_party/swagger-ui/README.md references https://github.com/swagger-api/swagger-ui#how-to-use-it but this anchor no longer exists in the upstream master branch.
  4. The swagger-ui distribution has version v2.1.1-M1. Upstream there are new releases (v2.2.10 and v3.2.0).

Would you mind an upgrade? Do you have any version preferences?

build fail

../../../../../github.com/philips/grpc-gateway-example/echopb/service.pb.gw.go:86: not enough arguments in call to runtime.AnnotateContext
        have ("golang.org/x/net/context".Context, *http.Request)
        want ("golang.org/x/net/context".Context, *runtime.ServeMux, *http.Request)
../../../../../github.com/philips/grpc-gateway-example/echopb/service.pb.gw.go:88: not enough arguments in call to runtime.HTTPError
        have ("golang.org/x/net/context".Context, runtime.Marshaler, http.ResponseWriter, *http.Request, error)
        want ("golang.org/x/net/context".Context, *runtime.ServeMux, runtime.Marshaler, http.ResponseWriter, *http.Request, error)
../../../../../github.com/philips/grpc-gateway-example/echopb/service.pb.gw.go:93: not enough arguments in call to runtime.HTTPError
        have ("golang.org/x/net/context".Context, runtime.Marshaler, http.ResponseWriter, *http.Request, error)
        want ("golang.org/x/net/context".Context, *runtime.ServeMux, runtime.Marshaler, http.ResponseWriter, *http.Request, error)
../../../../../github.com/philips/grpc-gateway-example/echopb/service.pb.gw.go:97: not enough arguments in call to forward_EchoService_Echo_0
        have ("golang.org/x/net/context".Context, runtime.Marshaler, http.ResponseWriter, *http.Request, proto.Message, []func("golang.org/x/net/context".Context, http.ResponseWriter, proto.Message) error...)
        want ("golang.org/x/net/context".Context, *runtime.ServeMux, runtime.Marshaler, http.ResponseWriter, *http.Request, proto.Message, ...func("golang.org/x/net/context".Context, http.ResponseWriter, proto.Message) error)

[Question] possible without tls

I'm attempting to terminate tls before hitting the grpc/rest gateway so I disabled the TLS certs in the code base and turned on grpc.WithInsecure, but I always end up with
{"error":"transport is closing","code":14}%

Parameter named 'body' causes confusion with message body

This comes from the OpenAPI (Swagger) Petstore example. http://petstore.swagger.io/v2/swagger.json

TLDR: A parameter named body causes this in the generated protobuf:

body: "body"

command

 openapi2proto -spec ~/Downloads/swagger.yaml -options > ~/xxx.proto

input

paths:
  /pet:
    post:
      tags:
      - "pet"
      summary: "Add a new pet to the store"
      operationId: "addPet"
      consumes:
      - "application/json"
      - "application/xml"
      produces:
      - "application/json"
      - "application/xml"
      parameters:
      - in: "body"
        name: "body"
        description: "Pet object that needs to be added to the store"
        required: true
        schema:
          $ref: "#/definitions/Pet"
      responses:
        405:
          description: "Invalid input"
      security:
      - petstore_auth:
        - "write:pets"
        - "read:pets"

output

service SwaggerPetstoreService {
    // Update an existing pet
    rpc UpdatePet(UpdatePetRequest) returns (google.protobuf.Empty) {
      option (google.api.http) = {
        put: "/dougfort/foot/1.0.0/pet"
        body: "body"
      };
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.