Git Product home page Git Product logo

dad-joke-service's Introduction

Dad Joke Service

Example of a microservice API written in gRPC and Protobuf.

The server is written in Golang, and there are two sample clients: one in PHP and one in Ruby.

This is an example to show how wrting microservices with gRPC and Protobuf can create APIs/services that are easily consumed in any of the major languages (supported by gRPC, such as PHP, Ruby, Python, C#, Java, and more).

Get this up and running

Getting this up and running can be a bit involved, since it does require several languages.

The easiest way is to use homebrew to install all this stuff:

Install Go.

brew install protobuf
brew install protobuf-c
brew install grpc

If you have issues installing the protobuf compiler, I recommend following the instructions on this blog post.

If you want to run the ruby client, I recommend using brew install rbenv to install the latest version of ruby.

For PHP, I also used homebrew to install composer.

Resources

Protobuf docs

gRPC docs / quickstart guide

Creating the necessary libraries

The libraries are already committed to source control here, but if you wanted a hand at re-generating them, or just want to know how, you have to run these commands:

For Golang:

protoc -I=proto —go_out=plugins=grpc:. proto/doggos.proto

Notice I am calling plugins=grpc to generate the grpc client and server code.

For Ruby and PHP

protoc -I proto --ruby_out=lib --grpc_out=lib --plugin=protoc-gen-grpc=`which grpc_ruby_plugin` proto/doggos.proto
protoc -I proto --php_out=grpc-client-php/lib --grpc_out=grpc-client-php/lib --plugin=protoc-gen-grpc=`which grpc_php_plugin` proto/doggos.proto

For PHP, you will also want to run composer install and pecl install grpc as well.

Start the mock server

cd grpc-server
go run main.go

Run the mock clients

Ruby

cd grpc-client-ruby
ruby dad_joke_client.rb

PHP

cd grpc-client-php
php dadJokeClient.php

dad-joke-service's People

Contributors

cecyc avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 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.