package
1.0.1
Repository: https://github.com/project-flogo/grpc.git
Documentation: pkg.go.dev

# README

REST to gRPC

This recipe demonstrates on receiving request from a Rest client and routing to gRPC server.

Installation

  • Install Go
  • Install protoc-gen-go library
go get github.com/golang/protobuf/protoc-gen-go
  • Download protoc for your respective OS from here.
    Extract protoc-$VERSION-$PLATFORM.zip file get the protoc binary from bin folder and configure it in PATH.

Setup

git clone https://github.com/project-flogo/grpc
cd grpc
go install
cd examples/json/rest-to-grpc

Create the gateway:

flogo create -f flogo.json
cd MyProxy
flogo install github.com/project-flogo/grpc/proto/rest2grpc
flogo build

Testing

Start gateway.

bin/MyProxy

Start sample gRPC server.

go run main.go -server

#1 Testing PetById method with GET request

Sample GET request.

curl --request GET http://localhost:9096/petstore/method/PetById?id=2

Now you should see logs in gateway terminal and sample gRPC server terminal. Output in curl request terminal can be seen as below.

{
 "pet": {
  "id": 2,
  "name": "cat2"
 }
}

#2 Testing UserByName method with GET request

Sample GET request.

curl --request GET http://localhost:9096/petstore/method/UserByName?username=user2

Output can be seen as below.

{
 "user": {
  "email": "email2",
  "id": 2,
  "phone": "phone2",
  "username": "user2"
 }
}

#3 Testing PetPUT method with PUT request

Payload

{
 "pet": {
  "id": 12,
  "name": "mycat12"
 }
}

Curl command

curl -X PUT "http://localhost:9096/petstore/PetPUT" -H "accept: application/xml" -H "Content-Type: application/json" -d '{"pet": {"id": 12,"name": "mycat12"}}'

Output can be seen as below.

{
 "pet": {
  "id": 12,
  "name": "mycat12"
 }
}