Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jnewmano/grpc-json-proxy
gRPC proxy for Postman like tools
https://github.com/jnewmano/grpc-json-proxy
Last synced: 3 months ago
JSON representation
gRPC proxy for Postman like tools
- Host: GitHub
- URL: https://github.com/jnewmano/grpc-json-proxy
- Owner: jnewmano
- License: mit
- Created: 2018-08-01T23:01:16.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-07-09T13:10:56.000Z (7 months ago)
- Last Synced: 2024-07-31T07:17:18.806Z (6 months ago)
- Language: Go
- Homepage:
- Size: 71.3 KB
- Stars: 517
- Watchers: 8
- Forks: 34
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - grpc-json-proxy - gRPC Proxy for Postman like tools (Go)
- my-awesome - jnewmano/grpc-json-proxy - 08 star:0.5k fork:0.0k gRPC proxy for Postman like tools (Go)
- awesome-grpc - grpc-json-proxy - A proxy which allows existing tools like Postman or curl to interact with gRPC servers (Tools / Other)
README
# grpc-json-proxy
GRPC JSON is a proxy which allows HTTP API tools like Postman to interact with gRPC servers.
## Requirements
- grpc+json codec must be enabled on the grpc server
- Postman must be configured to use the proxyConfiguration of the proxy and its dependencies is a three step process.
1. Register a JSON codec with the gRPC server. In Go, it can be automatically registered simple by adding the following import:
`import _"github.com/jnewmano/grpc-json-proxy/codec"`
If you're using `gogo/protobuf` as your protobuf backend, import the following:
`import _"github.com/jnewmano/grpc-json-proxy/gogoprotobuf/codec"`
2. Run the grpc-json-proxy. Download pre-built binaries from https://github.com/jnewmano/grpc-json-proxy/releases/ or build from source:
`go get -u github.com/jnewmano/grpc-json-proxy`
`grpc-json-proxy`
Other way, you can simply use `grpc-json-proxy` docker image out of the box:
```bash
docker run -p 7001:7001 jnewmano/grpc-json-proxy
```3. Configure Postman to send requests through the proxy.
Postman -> Preferences -> Proxy -> Global Proxy`Proxy Server: localhost 7001`
![Postman Proxy Configuration](https://cdn-images-1.medium.com/max/1600/1*oc09cwpCC9XrjpU9Gl5YTw.png)
Setup your Postman gRPC request with the following:
1. Set request method to Post .
1. Set the URL to http://{{ grpc server address}}/{{proto package}}.{{proto service}}/{{method}} Always use http, proxy will establish a secure connection to the gRPC server.
1. Set the Content-Type header to application/grpc+json .
1. Optionally add a Grpc-Insecure header set to true for an insecure connection.
1. Set the request body to appropriate JSON for the message. For reference, generated Go code includes JSON tags on the generated message structs.For example:
![Postman Example Request](https://cdn-images-1.medium.com/max/1600/1*npRlBiKxuJ5KMnnk0F5n6g.png)
Inspired by Johan Brandhorst's [grpc-json](https://jbrandhorst.com/post/grpc-json/)
### Host accessibility
If you use docker image to run grpc-json-proxy server, and want to access grpc via loopback address `127.0.0.1`, you should pay attention to docker network accessibility.
1. use `host.docker.internal` instead of `127.0.0.1` in Linux.
2. use `docker.for.mac.host.internal` instead of `127.0.0.1` in MacOS and with Docker for Mac 17.12 or above.See: https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds