Upgrade to Pro — share decks privately, control downloads, hide ads and more …

gRPC-webのここがすごい という話がしたかった

Hazumi Ichijo
November 19, 2018

gRPC-webのここがすごい という話がしたかった

Roppongi.js #7

Hazumi Ichijo

November 19, 2018
Tweet

More Decks by Hazumi Ichijo

Other Decks in Programming

Transcript

  1. ©2018 Wantedly, Inc. API Call \ lJEz  lOBNFzlH31$Λಋೖ͢Δz 

    lBVUIPSzlSFSPTUz  lEFBEMJOFzlz  lBQQMJDBUJPO@UZQFzl1$8FCz ^ Server Frontend
  2. ©2018 Wantedly, Inc. API Call \ lJEz  lOBNFzlH31$Λಋೖ͢Δz 

    lBVUIPSzlSFSPTUz  lEFBEMJOFzlz  lBQQMJDBUJPO@UZQFzl1$8FCz ^ Server Frontend ͜͜ͷϑΥʔϚοτ͸Կʁ
  3. ©2018 Wantedly, Inc. API Call \ lJEz  lOBNFzlH31$Λಋೖ͢Δz 

    lBVUIPSzlSFSPTUz  lEFBEMJOFzlz  lBQQMJDBUJPO@UZQFzl1$8FCz ^ Server Frontend ͜͜͸Կ͕ೖΔʁԿΛೖΕ͍͍ͯʁ - PC-Web or pc-web - iOS, Android, …?
  4. ©2018 Wantedly, Inc. gRPC Call Server Frontend message Todolist {

    int64 id = 1; string name = 2; string author = 3; google.protobuf.Timestamp deadline = 4; enum ApplicationType { PC_WEB = 0; MOBILE_WEB = 1; PC_APP = 2; IOS_APP = 3; ANDROID_APP = 4; } ApplicationType application_type = 5; }
  5. ©2018 Wantedly, Inc. gRPC Call Server Frontend service TodolistService {

    rpc ListTasks (ListTasksRequest) returns (ListTasksResponse) {} rpc GetTask (GetTaskRequest) returns (Todolist) {} rpc CreateTask (CreateTaskRequest) returns (Todolist) {} }
  6. ©2018 Wantedly, Inc. service TaskService { rpc ListTasks (ListTasksRequest) returns

    (ListTasksResponse) {} rpc GetTask (GetTaskRequest) returns (Task) {} rpc CreateTask (CreateTaskRequest) returns (Task) {} rpc UpdateTask (UpdateTaskRequest) returns (Task) {} rpc DeleteTask (DeleteTaskRequest) returns (google.protobuf.Empty) {} rpc StreamTask(CreateTaskRequest) returns (stream Task){} } message Task { int64 task_id = 1; string title = 2; google.protobuf.Timestamp created_at = 3; google.protobuf.Timestamp deadline = 4; google.protobuf.StringValue note = 5; } ϝοηʔδͷఆٛ αʔϏεͷఆٛ
  7. ©2018 Wantedly, Inc.  ϋϚΓ΍͍͢ w H31$ FOWPZ ʜ 

    ৘ใ͕গͳ͍ɾ୳ͮ͠Β͍ w JNQSPCBCMFFOHHSQDXFC͕ઌʹग़͍ͯͨͷͰݕࡧͯ͠΋͕ͬͪ͜Ҿ͔͔ͬΓ΍͍͢  ੜ੒͞ΕΔίʔυ͕ಡΊͳ͍ʢݸਓࠩ͋Γʣ
  8. ©2018 Wantedly, Inc. let req = new ListTasksRequest(); this.client.listTasks(req, {},

    (err, res) => { if (err != null) { // ԿΒ͔ͷΤϥʔॲཧ console.log(err); return; } this.setState({ tasks: res.getTasksList() }); }); let req = new CreateTaskRequest(); let task = new Task(); task.setTitle(this.state.text); req.setTask(task); this.client.createTask(req, {}, (err, res) => { if (err != null) { console.log(err); return; } this.setState({ tasks: [res, ...this.state.tasks] }); }); ίϯετϥΫλ͔ΒͰ͸ͳ͘ɺ`setXX`Ͱ౉͢ getterϝιου͕ࣗಈͰఆٛ͞Ε͍ͯΔ
  9. ©2018 Wantedly, Inc. /** * @fileoverview * @enhanceable * @suppress

    {messageConventions} JS Compiler reports an error if a variable or * field starts with 'MSG_' and isn't a translatable message. * @public */ // GENERATED CODE -- DO NOT EDIT! /* eslint-disable */ var jspb = require("google-protobuf"); var goog = jspb; var global = Function("return this")(); var google_protobuf_empty_pb = require("google-protobuf/google/protobuf/empty_pb.js"); var google_protobuf_timestamp_pb = require("google-protobuf/google/protobuf/timestamp_pb.js"); var google_protobuf_wrappers_pb = require("google-protobuf/google/protobuf/wrappers_pb.js"); var google_protobuf_field_mask_pb = require("google-protobuf/google/protobuf/field_mask_pb.js"); goog.exportSymbol( "proto.com.github.rerost.todolist_server.api.CreateTaskRequest", null, global ); goog.exportSymbol( "proto.com.github.rerost.todolist_server.api.DeleteTaskRequest", null, global ); goog.exportSymbol( "proto.com.github.rerost.todolist_server.api.GetTaskRequest", null, global ); goog.exportSymbol( "proto.com.github.rerost.todolist_server.api.ListTasksRequest", null, global ); goog.exportSymbol( "proto.com.github.rerost.todolist_server.api.ListTasksResponse", null, global ); goog.exportSymbol( "proto.com.github.rerost.todolist_server.api.Task", null, global ); goog.exportSymbol( "proto.com.github.rerost.todolist_server.api.UpdateTaskRequest", null, global ); ϝοηʔδͷఆٛ /** * @fileoverview gRPC-Web generated client stub for com.github.rerost.todolist_server.api * @enhanceable * @public */ // GENERATED CODE -- DO NOT EDIT! const grpc = {}; grpc.web = require("grpc-web"); var google_protobuf_empty_pb = require("google-protobuf/google/protobuf/empty_pb.js"); var google_protobuf_timestamp_pb = require("google-protobuf/google/protobuf/timestamp_pb.js"); var google_protobuf_wrappers_pb = require("google-protobuf/google/protobuf/wrappers_pb.js"); var google_protobuf_field_mask_pb = require("google-protobuf/google/protobuf/field_mask_pb.js"); const proto = {}; proto.com = {}; proto.com.github = {}; proto.com.github.rerost = {}; proto.com.github.rerost.todolist_server = {}; proto.com.github.rerost.todolist_server.api = require("./todo_pb.js"); /** * @param {string} hostname * @param {?Object} credentials * @param {?Object} options * @constructor * @struct * @final */ proto.com.github.rerost.todolist_server.api.TaskServiceClient = function( hostname, credentials, options ) { if (!options) options = {}; options["format"] = "text"; /** * @private @const {!grpc.web.GrpcWebClientBase} The client */ this.client_ = new grpc.web.GrpcWebClientBase(options); /** * @private @const {string} The hostname */ this.hostname_ = hostname; /** * @private @const {?Object} The credentials to be used to connect * to the server αʔϏεͷఆٛ