SlideShare a Scribd company logo
FROM ‘00s TO ‘20s:
FROM RESTful to gRPC
Gianfranco Reppucci
@giefferre Data Engineer
WHAT THIS TALK
IS ABOUT
BEFORE REST
S O A P
Common Object Request
Broker Architecture
Simple Object
Access Protocol
REST: REpresentational State Transfer
REST PRINCIPLES
Extension of the
web resource
concept
Identification of
resources with a
universal syntax
Resource
accessibility via a
universal interface
REST ARCHITECTURAL ELEMENTS
DATA ELEMENTS CONNECTORS COMPONENTS
REPRESENTATIONSURIsRESOURCES
REST CONSTRAINTS
Client - Server Stateless Cacheability
Uniform Interface Layered System Code On Demand
SO, WHAT’S THE
PROBLEM WITH REST?
RELATIONSHIP BETWEEN URIs
AND HTTP VERBS / 1
GET PUT PATCH
POST DELETE
List of URIs (w/other details?) of all
the person items in the database
Replace the entire persons
dataset with a new one
Not generally used
ok...
Add a new person
to the dataset
Delete the entire persons
dataset
https://api.example.com/persons
RELATIONSHIP BETWEEN URIs
AND HTTP VERBS / 2
Retrieve the person matching
the given identifier “123”
Replace the addressed
person with a new one
Update the addressed person
with the given fields
Not generally used
uhm...
Delete the addressed person
from the dataset
https://api.example.com/persons/123
GET PUT PATCH
POST DELETE
RESTful IS EVIL
FULL LIST OF HTTP VERBS
OPTIONS GET POSTHEAD
PUT DELETE CONNECTTRACE
ツ
FULL LIST OF HTTP STATUS CODES / 1
INFORMATIONAL SUCCESS REDIRECTION
100, 101, 102, 103 200, 201, 203, 204,
205, 206, 207, 208,
226
300, 301, 302, 303,
304, 305, 306, 307,
308
FULL LIST OF HTTP STATUS CODES / 1
CLIENT
ERRORS
SERVER
ERRORS
UNOFFICIAL
CODES
400, 401, 402, 403,
404, 405, 406, 407,
408, 409, 410, 411,
412, 413, 414, 415,
416, 417, 418, 421,
422, 423, 424, 426,
428, 429, 431, 451
500, 501, 502, 503,
504, 505, 506, 507,
508, 510, 511
103, 218, 420, 450,
498, 499, 509, 530,
598, many more...
PROBLEMS OF
RESTful APIs
#1
LITTLE AGREEMENT ON WHAT “RESTful” MEANS
#2
REST VOCABULARY IS NOT FULLY SUPPORTED
#3
REST VOCABULARY IS NOT RICH ENOUGH FOR A COMPLETE API
#4
RESTful APIs ARE TIED TO HTTP
H T T P
MOVING FORWARD
JSON - RPC
STATELESS LIGHTWEIGHT TRANSPORT
AGNOSTIC
USES JSON AS
DATA FORMAT
SUPPORTS
NOTIFICATION REQUEST
JSON - RPC : REQUEST
{
"jsonrpc": "2.0",
"method": "DemoRPCService.CreatePerson",
"params": {
"name": "Gianfranco",
"surname": "Reppucci",
"age": 36
},
"id": 1234567
}
JSON - RESPONSE
{
"jsonrpc": "2.0",
"result": {
"id": "bcjsuge8t5ekk4rj6b4g",
"name": "Gianfranco",
"surname": "Reppucci",
"age": 36
},
"id": 1234567
}
JSON - RPC : NOTIFICATION
{
"jsonrpc": "2.0",
"method": "DemoRPCService.CheckForNewPersons"
}
JSON - RPC : ERROR
{
"jsonrpc": "2.0",
"error": {
"code": -32000,
"message": "person: invalid name or surname
given",
"data": null
},
"id": 1234567
}
BATCH REQUESTS
Useful to aggregate
multiple requests
Server is obliged to respond to
every non-Notification request
JSON-RPC ADVANTAGES
Readability Ease of encoding /
decoding
Separation from
transport protocol
JSON-RPC DISADVANTAGES
No binary
encoding
Ease to mess up
method names
github.com/giefferre/jsonrpc-usage-example
MOVING FAST FORWARD
gRPC
Open Source Remote
Procedure Call protocol
Developed initially
at Google
Uses HTTP/2
for transport
Protocol Buffers as
Interface Description Language
gRPC: PRINCIPLES
Services, not Objects
Messages, not
References
Built-in support for 10
languages across multiple
environments
Blocking /
Non Blocking
(Bidirectional)
Streaming
Cancellation &
Timeout
Flow
Control
Standardized
Status Codes
DEFINITION OF A SAMPLE SERVICE / 1
message Person {
string id = 1; // Unique ID for this person.
string name = 2;
string surname = 3;
uint32 age = 4;
}
DEFINITION OF A SAMPLE SERVICE / 2
message CreatePersonArgs {
string name = 1;
string surname = 2;
uint32 age = 3;
}
message ReadPersonArgs {
string id = 1;
}
DEFINITION OF A SAMPLE SERVICE / 3
service DemoRPCService {
rpc CreatePerson (CreatePersonArgs) returns (Person) {}
rpc ReadPerson (ReadPersonArgs) returns (Person) {}
}
WRITING A SERVER IN GO / 1
type demoRPCServer struct {
...
}
func (s *demoRPCServer) CreatePerson
(ctx context.Context, args *CreatePersonArgs) (*Person, error) {
...
}
func (s *demoRPCServer) ReadPerson
(ctx context.Context, args *ReadPersonArgs) (*Person, error) {
...
}
WRITING A SERVER IN GO / 2
func main() {
listener, err := net.Listen("tcp", ":1234")
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
grpcServer := grpc.NewServer()
RegisterDemoRPCServiceServer(grpcServer, &demoRPCServer{})
grpcServer.Serve(listener)
}
WRITING A CLIENT IN PYTHON
channel = grpc.insecure_channel('localhost:6000')
client = rpcservice.DemoRPCServiceStub(channel)
new_person = client.CreatePerson(
pb.CreatePersonArgs(
name='John',
surname='Doe',
age=36,
)
)
github.com/giefferre/grpc-usage-example
CONCLUSIONS
REST concepts are solid,
RESTful implementations
aren’t
*RPC alternatives
are valid
You can take advantages of
some REST concepts when
developing *RPC services
JSON-RPC and gRPC are
modern and they can be
pretty powerful
JOIN US
THANK YOU
Gianfranco Reppucci
@giefferre Data Engineer

More Related Content

Similar to From '00s to '20s: from RESTful to gRPC

Introduction to JSON & AJAX
Introduction to JSON & AJAXIntroduction to JSON & AJAX
Introduction to JSON & AJAX
Raveendra R
 
REST to GraphQL migration: Pros, cons and gotchas
REST to GraphQL migration: Pros, cons and gotchasREST to GraphQL migration: Pros, cons and gotchas
REST to GraphQL migration: Pros, cons and gotchas
Alexey Ivanov
 
"R, HTTP, and APIs, with a preview of TopicWatchr" (15 November 2011)
"R, HTTP, and APIs, with a preview of TopicWatchr" (15 November 2011)"R, HTTP, and APIs, with a preview of TopicWatchr" (15 November 2011)
"R, HTTP, and APIs, with a preview of TopicWatchr" (15 November 2011)
Portland R User Group
 
R, HTTP, and APIs, with a preview of TopicWatchr
R, HTTP, and APIs, with a preview of TopicWatchrR, HTTP, and APIs, with a preview of TopicWatchr
R, HTTP, and APIs, with a preview of TopicWatchr
Portland R User Group
 
FIWARE Training: JSON-LD and NGSI-LD
FIWARE Training: JSON-LD and NGSI-LDFIWARE Training: JSON-LD and NGSI-LD
FIWARE Training: JSON-LD and NGSI-LD
FIWARE
 
Life on Clouds: a forensics overview
Life on Clouds: a forensics overviewLife on Clouds: a forensics overview
Life on Clouds: a forensics overview
Reality Net System Solutions
 
Introduction to Hydra
Introduction to HydraIntroduction to Hydra
Introduction to Hydra
Alejandro Inestal
 
GraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learnedGraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learned
MarcinStachniuk
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Hypermedia APIs and HATEOAS / Wix Engineering
Hypermedia APIs and HATEOAS / Wix EngineeringHypermedia APIs and HATEOAS / Wix Engineering
Hypermedia APIs and HATEOAS / Wix Engineering
Vladimir Tsukur
 
JSON and REST
JSON and RESTJSON and REST
JSON and REST
Robert MacLean
 
Arabidopsis Information Portal, Developer Workshop 2014, Introduction
Arabidopsis Information Portal, Developer Workshop 2014, IntroductionArabidopsis Information Portal, Developer Workshop 2014, Introduction
Arabidopsis Information Portal, Developer Workshop 2014, Introduction
JasonRafeMiller
 
Session 2 - NGSI-LD primer & Smart Data Models | Train the Trainers Program
Session 2 - NGSI-LD primer & Smart Data Models | Train the Trainers ProgramSession 2 - NGSI-LD primer & Smart Data Models | Train the Trainers Program
Session 2 - NGSI-LD primer & Smart Data Models | Train the Trainers Program
FIWARE
 
Yet another json rpc library (mole rpc)
Yet another json rpc library (mole rpc)Yet another json rpc library (mole rpc)
Yet another json rpc library (mole rpc)
Viktor Turskyi
 
PLNOG 18 - Piotr Wojciechowski - REST API czyli jak miękko wejść w programowa...
PLNOG 18 - Piotr Wojciechowski - REST API czyli jak miękko wejść w programowa...PLNOG 18 - Piotr Wojciechowski - REST API czyli jak miękko wejść w programowa...
PLNOG 18 - Piotr Wojciechowski - REST API czyli jak miękko wejść w programowa...
PROIDEA
 
FIWARE Training: JSON-LD and NGSI-LD
FIWARE Training: JSON-LD and NGSI-LDFIWARE Training: JSON-LD and NGSI-LD
FIWARE Training: JSON-LD and NGSI-LD
FIWARE
 
Restful webservices
Restful webservicesRestful webservices
Restful webservices
Kong King
 
Synchronize AD and OpenLDAP with LSC
Synchronize AD and OpenLDAP with LSCSynchronize AD and OpenLDAP with LSC
Synchronize AD and OpenLDAP with LSCLDAPCon
 
JSON-LD and NGSI-LD
JSON-LD and NGSI-LDJSON-LD and NGSI-LD
JSON-LD and NGSI-LD
FIWARE
 

Similar to From '00s to '20s: from RESTful to gRPC (20)

Introduction to JSON & AJAX
Introduction to JSON & AJAXIntroduction to JSON & AJAX
Introduction to JSON & AJAX
 
REST to GraphQL migration: Pros, cons and gotchas
REST to GraphQL migration: Pros, cons and gotchasREST to GraphQL migration: Pros, cons and gotchas
REST to GraphQL migration: Pros, cons and gotchas
 
"R, HTTP, and APIs, with a preview of TopicWatchr" (15 November 2011)
"R, HTTP, and APIs, with a preview of TopicWatchr" (15 November 2011)"R, HTTP, and APIs, with a preview of TopicWatchr" (15 November 2011)
"R, HTTP, and APIs, with a preview of TopicWatchr" (15 November 2011)
 
R, HTTP, and APIs, with a preview of TopicWatchr
R, HTTP, and APIs, with a preview of TopicWatchrR, HTTP, and APIs, with a preview of TopicWatchr
R, HTTP, and APIs, with a preview of TopicWatchr
 
FIWARE Training: JSON-LD and NGSI-LD
FIWARE Training: JSON-LD and NGSI-LDFIWARE Training: JSON-LD and NGSI-LD
FIWARE Training: JSON-LD and NGSI-LD
 
Life on Clouds: a forensics overview
Life on Clouds: a forensics overviewLife on Clouds: a forensics overview
Life on Clouds: a forensics overview
 
Introduction to Hydra
Introduction to HydraIntroduction to Hydra
Introduction to Hydra
 
GraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learnedGraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learned
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Switch to Backend 2023
 
Hypermedia APIs and HATEOAS / Wix Engineering
Hypermedia APIs and HATEOAS / Wix EngineeringHypermedia APIs and HATEOAS / Wix Engineering
Hypermedia APIs and HATEOAS / Wix Engineering
 
JSON and REST
JSON and RESTJSON and REST
JSON and REST
 
Arabidopsis Information Portal, Developer Workshop 2014, Introduction
Arabidopsis Information Portal, Developer Workshop 2014, IntroductionArabidopsis Information Portal, Developer Workshop 2014, Introduction
Arabidopsis Information Portal, Developer Workshop 2014, Introduction
 
Session 2 - NGSI-LD primer & Smart Data Models | Train the Trainers Program
Session 2 - NGSI-LD primer & Smart Data Models | Train the Trainers ProgramSession 2 - NGSI-LD primer & Smart Data Models | Train the Trainers Program
Session 2 - NGSI-LD primer & Smart Data Models | Train the Trainers Program
 
Yet another json rpc library (mole rpc)
Yet another json rpc library (mole rpc)Yet another json rpc library (mole rpc)
Yet another json rpc library (mole rpc)
 
PLNOG 18 - Piotr Wojciechowski - REST API czyli jak miękko wejść w programowa...
PLNOG 18 - Piotr Wojciechowski - REST API czyli jak miękko wejść w programowa...PLNOG 18 - Piotr Wojciechowski - REST API czyli jak miękko wejść w programowa...
PLNOG 18 - Piotr Wojciechowski - REST API czyli jak miękko wejść w programowa...
 
FIWARE Training: JSON-LD and NGSI-LD
FIWARE Training: JSON-LD and NGSI-LDFIWARE Training: JSON-LD and NGSI-LD
FIWARE Training: JSON-LD and NGSI-LD
 
126 Golconde
126 Golconde126 Golconde
126 Golconde
 
Restful webservices
Restful webservicesRestful webservices
Restful webservices
 
Synchronize AD and OpenLDAP with LSC
Synchronize AD and OpenLDAP with LSCSynchronize AD and OpenLDAP with LSC
Synchronize AD and OpenLDAP with LSC
 
JSON-LD and NGSI-LD
JSON-LD and NGSI-LDJSON-LD and NGSI-LD
JSON-LD and NGSI-LD
 

Recently uploaded

openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
Google
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
Roshan Dwivedi
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 

Recently uploaded (20)

openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 

From '00s to '20s: from RESTful to gRPC

  • 1. FROM ‘00s TO ‘20s: FROM RESTful to gRPC Gianfranco Reppucci @giefferre Data Engineer
  • 3. BEFORE REST S O A P Common Object Request Broker Architecture Simple Object Access Protocol
  • 5. REST PRINCIPLES Extension of the web resource concept Identification of resources with a universal syntax Resource accessibility via a universal interface
  • 6. REST ARCHITECTURAL ELEMENTS DATA ELEMENTS CONNECTORS COMPONENTS REPRESENTATIONSURIsRESOURCES
  • 7. REST CONSTRAINTS Client - Server Stateless Cacheability Uniform Interface Layered System Code On Demand
  • 9. RELATIONSHIP BETWEEN URIs AND HTTP VERBS / 1 GET PUT PATCH POST DELETE List of URIs (w/other details?) of all the person items in the database Replace the entire persons dataset with a new one Not generally used ok... Add a new person to the dataset Delete the entire persons dataset https://api.example.com/persons
  • 10. RELATIONSHIP BETWEEN URIs AND HTTP VERBS / 2 Retrieve the person matching the given identifier “123” Replace the addressed person with a new one Update the addressed person with the given fields Not generally used uhm... Delete the addressed person from the dataset https://api.example.com/persons/123 GET PUT PATCH POST DELETE
  • 12. FULL LIST OF HTTP VERBS OPTIONS GET POSTHEAD PUT DELETE CONNECTTRACE
  • 13.
  • 14. FULL LIST OF HTTP STATUS CODES / 1 INFORMATIONAL SUCCESS REDIRECTION 100, 101, 102, 103 200, 201, 203, 204, 205, 206, 207, 208, 226 300, 301, 302, 303, 304, 305, 306, 307, 308
  • 15. FULL LIST OF HTTP STATUS CODES / 1 CLIENT ERRORS SERVER ERRORS UNOFFICIAL CODES 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 421, 422, 423, 424, 426, 428, 429, 431, 451 500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511 103, 218, 420, 450, 498, 499, 509, 530, 598, many more...
  • 16.
  • 18. #1 LITTLE AGREEMENT ON WHAT “RESTful” MEANS
  • 19. #2 REST VOCABULARY IS NOT FULLY SUPPORTED
  • 20. #3 REST VOCABULARY IS NOT RICH ENOUGH FOR A COMPLETE API
  • 21. #4 RESTful APIs ARE TIED TO HTTP H T T P
  • 23. JSON - RPC STATELESS LIGHTWEIGHT TRANSPORT AGNOSTIC USES JSON AS DATA FORMAT SUPPORTS NOTIFICATION REQUEST
  • 24. JSON - RPC : REQUEST { "jsonrpc": "2.0", "method": "DemoRPCService.CreatePerson", "params": { "name": "Gianfranco", "surname": "Reppucci", "age": 36 }, "id": 1234567 }
  • 25. JSON - RESPONSE { "jsonrpc": "2.0", "result": { "id": "bcjsuge8t5ekk4rj6b4g", "name": "Gianfranco", "surname": "Reppucci", "age": 36 }, "id": 1234567 }
  • 26. JSON - RPC : NOTIFICATION { "jsonrpc": "2.0", "method": "DemoRPCService.CheckForNewPersons" }
  • 27. JSON - RPC : ERROR { "jsonrpc": "2.0", "error": { "code": -32000, "message": "person: invalid name or surname given", "data": null }, "id": 1234567 }
  • 28. BATCH REQUESTS Useful to aggregate multiple requests Server is obliged to respond to every non-Notification request
  • 29. JSON-RPC ADVANTAGES Readability Ease of encoding / decoding Separation from transport protocol
  • 33. gRPC Open Source Remote Procedure Call protocol Developed initially at Google Uses HTTP/2 for transport Protocol Buffers as Interface Description Language
  • 34. gRPC: PRINCIPLES Services, not Objects Messages, not References Built-in support for 10 languages across multiple environments Blocking / Non Blocking (Bidirectional) Streaming Cancellation & Timeout Flow Control Standardized Status Codes
  • 35. DEFINITION OF A SAMPLE SERVICE / 1 message Person { string id = 1; // Unique ID for this person. string name = 2; string surname = 3; uint32 age = 4; }
  • 36. DEFINITION OF A SAMPLE SERVICE / 2 message CreatePersonArgs { string name = 1; string surname = 2; uint32 age = 3; } message ReadPersonArgs { string id = 1; }
  • 37. DEFINITION OF A SAMPLE SERVICE / 3 service DemoRPCService { rpc CreatePerson (CreatePersonArgs) returns (Person) {} rpc ReadPerson (ReadPersonArgs) returns (Person) {} }
  • 38. WRITING A SERVER IN GO / 1 type demoRPCServer struct { ... } func (s *demoRPCServer) CreatePerson (ctx context.Context, args *CreatePersonArgs) (*Person, error) { ... } func (s *demoRPCServer) ReadPerson (ctx context.Context, args *ReadPersonArgs) (*Person, error) { ... }
  • 39. WRITING A SERVER IN GO / 2 func main() { listener, err := net.Listen("tcp", ":1234") if err != nil { log.Fatalf("failed to listen: %v", err) } grpcServer := grpc.NewServer() RegisterDemoRPCServiceServer(grpcServer, &demoRPCServer{}) grpcServer.Serve(listener) }
  • 40. WRITING A CLIENT IN PYTHON channel = grpc.insecure_channel('localhost:6000') client = rpcservice.DemoRPCServiceStub(channel) new_person = client.CreatePerson( pb.CreatePersonArgs( name='John', surname='Doe', age=36, ) )
  • 42. CONCLUSIONS REST concepts are solid, RESTful implementations aren’t *RPC alternatives are valid You can take advantages of some REST concepts when developing *RPC services JSON-RPC and gRPC are modern and they can be pretty powerful