from 00s to 20s
play

FROM 00s TO 20s: FROM REST ful to gRPC Gianfranco Reppucci - PowerPoint PPT Presentation

FROM 00s TO 20s: FROM REST ful to gRPC Gianfranco Reppucci @giefferre Data Engineer WHAT THIS TALK IS ABOUT BEFORE REST S O A P Common Object Request Simple Object Broker Architecture Access Protocol REST: REpresentational State


  1. FROM ‘00s TO ‘20s: FROM REST ful to gRPC Gianfranco Reppucci @giefferre Data Engineer

  2. WHAT THIS TALK IS ABOUT

  3. BEFORE REST S O A P Common Object Request Simple Object Broker Architecture Access Protocol

  4. REST: REpresentational State Transfer

  5. REST PRINCIPLES Extension of the Identification of Resource web resource resources with a accessibility via a concept universal syntax universal interface

  6. REST ARCHITECTURAL ELEMENTS DATA ELEMENTS CONNECTORS COMPONENTS RESOURCES URIs REPRESENTATIONS

  7. REST CONSTRAINTS Client - Server Stateless Cacheability Uniform Interface Layered System Code On Demand

  8. SO, WHAT’S THE PROBLEM WITH REST?

  9. RELATIONSHIP BETWEEN URIs AND HTTP VERBS / 1 https://api.example.com/persons GET PUT PATCH List of URIs (w/other details?) of all Replace the entire persons Not generally used the person items in the database dataset with a new one ok ... POST DELETE Add a new person Delete the entire persons to the dataset dataset

  10. RELATIONSHIP BETWEEN URIs AND HTTP VERBS / 2 https://api.example.com/persons/123 GET PUT PATCH Retrieve the person matching Replace the addressed Update the addressed person the given identifier “123” person with a new one with the given fields POST DELETE Not generally used Delete the addressed person uhm ... from the dataset

  11. REST ful IS EVIL

  12. FULL LIST OF HTTP VERBS OPTIONS GET HEAD POST PUT DELETE TRACE CONNECT

  13. ¯\_( ツ )_/¯

  14. FULL LIST OF HTTP STATUS CODES / 1 INFORMATIONAL SUCCESS REDIRECTION 100, 101, 102, 103 200, 201, 203, 204, 300, 301, 302, 303, 205, 206, 207, 208, 304, 305, 306, 307, 226 308

  15. FULL LIST OF HTTP STATUS CODES / 1 CLIENT SERVER UNOFFICIAL ERRORS ERRORS CODES 400, 401, 402, 403, 500, 501, 502, 503, 103, 218, 420, 450, 404, 405, 406, 407, 504, 505, 506, 507, 498, 499, 509, 530, 408, 409, 410, 411, 508, 510, 511 598, many more... 412, 413, 414, 415, 416, 417, 418 , 421, 422, 423, 424, 426, 428, 429, 431, 451

  16. PROBLEMS OF RESTful APIs

  17. #1 LITTLE AGREEMENT ON WHAT “RESTful” MEANS

  18. #2 REST VOCABULARY IS NOT FULLY SUPPORTED

  19. #3 REST VOCABULARY IS NOT RICH ENOUGH FOR A COMPLETE API

  20. #4 RESTful APIs ARE TIED TO HTTP H T T P

  21. MOVING FORWARD

  22. JSON - RPC STATELESS LIGHTWEIGHT TRANSPORT AGNOSTIC USES JSON AS SUPPORTS DATA FORMAT NOTIFICATION REQUEST

  23. JSON - RPC : REQUEST { " jsonrpc ": "2.0", " method ": "DemoRPCService.CreatePerson", " params ": { "name": "Gianfranco", "surname": "Reppucci", "age": 36 }, " id ": 1234567 }

  24. JSON - RESPONSE { " jsonrpc ": "2.0", " result ": { "id": "bcjsuge8t5ekk4rj6b4g", "name": "Gianfranco", "surname": "Reppucci", "age": 36 }, " id ": 1234567 }

  25. JSON - RPC : NOTIFICATION { " jsonrpc ": "2.0", " method ": "DemoRPCService.CheckForNewPersons" }

  26. JSON - RPC : ERROR { " jsonrpc ": "2.0", " error ": { " code ": -32000, " message ": "person: invalid name or surname given", "data": null }, " id ": 1234567 }

  27. BATCH REQUESTS Useful to aggregate Server is obliged to respond to multiple requests every non-Notification request

  28. JSON-RPC ADVANTAGES Readability Ease of encoding / Separation from decoding transport protocol

  29. JSON-RPC DISADVANTAGES No binary Ease to mess up encoding method names

  30. github.com/giefferre/jsonrpc-usage-example

  31. MOVING FAST FORWARD

  32. gRPC Open Source Remote Developed initially Procedure Call protocol at Google Uses HTTP/2 Protocol Buffers as for transport Interface Description Language

  33. gRPC: PRINCIPLES Services, not Objects Built-in support for 10 (Bidirectional) Blocking / Messages, not languages across multiple Streaming Non Blocking References environments Cancellation & Flow Standardized Timeout Control Status Codes

  34. 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 ; }

  35. DEFINITION OF A SAMPLE SERVICE / 2 message CreatePersonArgs { string name = 1; string surname = 2; uint32 age = 3; } message ReadPersonArgs { string id = 1; }

  36. DEFINITION OF A SAMPLE SERVICE / 3 service DemoRPCService { rpc CreatePerson ( CreatePersonArgs ) returns ( Person ) {} rpc ReadPerson (ReadPersonArgs) returns (Person) {} }

  37. 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) { ... }

  38. 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) }

  39. 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, ) )

  40. github.com/giefferre/grpc-usage-example

  41. CONCLUSIONS REST concepts are solid, *RPC alternatives REST ful implementations are valid aren’t You can take advantages of JSON-RPC and gRPC are some REST concepts when modern and they can be developing *RPC services pretty powerful

  42. JOIN US careers.cubeyou.com

  43. THANK YOU Gianfranco Reppucci @giefferre Data Engineer

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend