15
Ditching REST for gRPC Steve High CPOSC 2017

Ditching REST for gRPC - CPOSCcposc.org/.../2017/11/CPOSC2017-DitchRESTForgRPC.pdf · REST REpresentational State Transfer • 95.3% of APIs that are RESTful aren’t RESTful* •

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Ditching REST for gRPC

Steve HighCPOSC 2017

RESTREpresentational State Transfer

• 95.3% of APIs that are RESTful aren’t RESTful*• I just made that up, but it sounds right

• The original intent of REST was to communicate state

RESTHow people use REST

• Define a route• Match the route to an HTTP verb• Assign a handler to the route/verb pair• Return some JSON

RESTIsn’t REST just RPC masquerading as something less antiquated?• Handlers smell a lot like RPC calls• At least it isn’t SOAP!

RPCRemote Procedure Call

• Call a remote function like it was part of your program• A menagerie of protocols

• Windows Communication Foundation• XML-RPC• JSON-RPC• AMF• … and several dozen more

• Great if you commit to one architecture or stack

• Not so great if you have a diversity of services

gRPC?Google’s Good Remote Procedure Calling

• Google• Open Source!• Stack-Agnostic

gRPC?Protocol Buffers• Objects are converted to an indexable byte format• No serialization/deserialization

gRPC?HTTP/2• Derived from Google’s SPDY protocol• Formal specification (RFC 7540) published May 2015• Header compression• Bidirectional with server push• Multiplexes multiple requests over one TCP connection

Protobuf DSL

syntax = "proto3";

package mathservice;

service MathService { rpc Add(AddRequest) returns (AddResponse); rpc Average(AverageRequest) returns (AverageResponse); }

Ditching REST for gRPC

Protobuf DSLmessage AddRequest { int64 addend1 = 1; int64 addend2 = 2; }

message AddResponse { int64 sum = 1; }

message AverageRequest { repeated int64 numbers = 1; }

message AverageResponse { float average = 1; }

Ditching REST for gRPC

Ditching REST for gRPC

mathservice.proto

protoc —go_out=plugins=grpc:. mathservice.proto

mathservice.pb.go

Ditching REST for gRPC

mathservice.pb.gomath service server

mathservice.pb.go

math service client

mathservice.pb.go

math service client

mathservice.pb.go

math service client

mathservice.pb.go

math service client

Ditching REST for gRPC

DEMO

Ditching REST for gRPC

Links

https://github.com/schigh/cposc2017_mathserviceMath service definition

https://github.com/schigh/cposc2017_mathservice_appMath service client and server app

https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htmREST white paper

https://developers.google.com/protocol-buffers/docs/encodingProtocol buffer encoding guide

https://grpc.io/gRPC website

https://developers.google.com/protocol-buffers/docs/reference/overviewProtocol buffer API reference

https://developers.google.com/protocol-buffers/Protocol buffer intro