Giter Site home page Giter Site logo

yoyonel / grpc-rest-swagger Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stevefox/grpc-rest-swagger

0.0 2.0 0.0 34 KB

Proof of concept for using gRPC, REST and Swagger together for building microservices.

License: MIT License

Makefile 24.44% Shell 4.09% Python 55.21% Go 16.26%

grpc-rest-swagger's Introduction

This is an experiment for writing gRPC services that can be easily exposed as HTTP/2 compatible REST interfaces. They also have built-in validation and the entire Swagger Tools ecosystem.

This is a great design pattern if you want to gRPC for most of your APIs, but still expose an HTTP API (for example, to make it easier for javascript clients to consume an API).

Set up

  1. Install swagger extras (goget.sh)
  2. Write the service.proto using import "google/api/annotations.proto";
  3. Compile your services to the target language
    • Use the default target in the Makefile, make
    • Known issue generating python services grpc/grpc#4961
  4. Install go depedencies:
    • export GOPATH=$(pwd)/gopath
    • go get .` to install dependencies in main.go

To Run the Services:

  1. Start the proxy gateway
    • go run main.go
  2. Run the python server and client:
    • Add the generated python code to your python path
      • export PYTHONPATH=gen/python
    • Start the backend gRPC service
      • python3 service_impl.py
    • Run the gRPC client
      • python3 service_client.py which accesses the backend gRPC service directly
  3. Access via HTTP
    • curl -X POST -H "Content-Type: application/json" "http://localhost:50052/v1/example/echo" -d '{}'

See the Swagger Docs (using Docker)

  • Run ./docs.sh, which starts a docker container for swagger-ui

Generate HTTP client libraries using Swgager

  • mkdir -p gen/swagger_gen/python
  • docker pull swaggerapi/swagger-codegen-cli
  • docker run --user ${UID} -v $(pwd)/gen:/local swaggerapi/swagger-codegen-cli generate -i /local/service.swagger.json -l python -o /local/swagger_gen/python

Using Swagger client libraries

Swagger Codegen generates documentation and usage examples. See gen/swagger_gen/python/README.md for automatically generated client documentation.

grpc-rest-swagger's People

Contributors

stevefox avatar

Watchers

 avatar  avatar

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.