Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

cecyc/dad-joke-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Microservice / API written with gRPC + protobuf, with Golang server, PHP and Ruby clients

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors