Giter Site home page Giter Site logo

grpc-on-rails's Introduction

grpc-on-rails (experiment)

I'm experimenting with having a gRPC API attached to a Rails app. By having it attached to the same codebase, one can start to extract an API from the code inside the application. When all calls are encapsulated in gRPC, one can split the repo into two and make them two different applications.

Current implementation

I see no way of having both the Rails server and the gRPC server served in the same process on the same port. One could probably use the same process using threads, but that's just silly IMO.

Server is implemented as a separate server that still has optional access to the codebase in the Rails app.

Rails has an API client implementation it can use to talk to this separate process.

Running this yourself

Install dependencies:

bundle install

Start the gRPC server:

cd api && ./bin/api-server

It'll tell you the address that the server is bound to, which is required for the next step.

Start the Rails application:

rake db:setup
API_URL=<ADDRESS_OF_THE_API_SERVER> ./bin/rails server

Calling the API

You can call it using curl:

curl -s localhost:3000/api/v2/announcements | python -mjson.tool

Code generation

Both apps have Rake tasks for generating code. It's not very clever right now, but call rake protos in the API app, then rake protos:copy in the Rails app to copy the results into the Rails app.

This could simulate a new API server version being developed and deployed without the Rails app getting the new definitions yet.

Thoughts so far

  • The gRPC module requires us to override the logger methods to get a log. Sounds a bit strange, but okay.
  • If a server implementation crashes, the gRPC server does not go down.
    • How can I catch these errors? I want to die in some cases, or at least send these errors somewhere. It seems to just log them.
    • I've had several errors that just hangs the process completely. Would this be avoided using tests? Is this only happening when the server is actually listening?
  • Documentation is still very basic and hard to grasp.
  • The generated code is super duper simple. Should probably invest in some sort of "active record"-like decorator.
  • How hard would it be to attach a grpc-gateway JSON-API inside the Rails app? It would be cool to mount it somehow so the Rails app can be a proxy to the gRPC API for older clients.
  • Making clients are super duper ultra simple. Nice!
  • How can I pass metadata like request ID?
  • How do I test the server?

grpc-on-rails's People

Contributors

mange avatar

Watchers

Glenn Nagel avatar James Cloos 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.