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

Proto definition file (.proto file) で JSON API ...

Nao Minami
January 29, 2019

Proto definition file (.proto file) で JSON API の schema を管理する

Meguro.rb#23 で「Proto definition file (.proto file) で JSON API の schema を管理する」という発表をしました!
https://megurorb.connpass.com/event/115497/

Nao Minami

January 29, 2019
Tweet

More Decks by Nao Minami

Other Decks in Technology

Transcript

  1. ©2018 Wantedly, Inc. Proto definition file (.proto file) Ͱ JSON

    API ͷ schema Λ؅ཧ͢Δ 29.Jan.2019 - Nao Minami (@south37) Wantedly, Inc. Meguro.rb#23
  2. ©2018 Wantedly, Inc. /BP.JOBNJ *OGSBTUSVDUVSF&OHJOFFS 8BOUFEMZ *OD (JU)VCTPVUI 5XJUUFSTPVUI 

    43&ͱͯ͠ͷ໾ׂʢαʔϏεͷ৴པੑʹ੹೚ʣ  ։ൃج൫ͱͯ͠ͷ໾ׂʢΤϯδχΞͷੜ࢈ੑʹ੹೚ʣ
  3. ©2018 Wantedly, Inc. w .JDSPTFSWJDFTͷϝϦοτ w ٕज़ҟ࣭ੑ w εέʔϦϯά w

    σϓϩΠ༰қੑ w ૊৫໘ͷҰக w FUD .JDSPTFSWJDFT ग़యʰϚΠΫϩαʔϏεΞʔΩςΫνϟʱΦϥΠϦʔɾδϟύϯ
  4. ©2018 Wantedly, Inc. w .JDSPTFSWJDFTͷཧ૝తͳ౷߹ٕज़ w ഁյతมߋΛճආͰ͖Δ w "1*͕ٕज़ඇґଘ w

    ίϯγϡʔϚʹͱͬͯ୯७ͳαʔϏε w ಺෦ͷ࣮૷ৄࡉΛӅ͢ .JDSPTFSWJDFTͷ౷߹ٕज़ ग़యʰϚΠΫϩαʔϏεΞʔΩςΫνϟʱΦϥΠϦʔɾδϟύϯ
  5. ©2018 Wantedly, Inc. w HSQDͷಛ௃ w 1SPUPDPM#V⒎FSpMF QSPUPpMF ʹΑΔ TDIFNB؅ཧ

    w CJOBSZGPSNBUͱTFSJBMJ[FEFTFSJBMJ[F ίʔυͷࣗಈੜ੒ w )551Λར༻ͨ͠ޮ཰తͳUSBOTQPSU HSQDͱ͸
  6. ©2018 Wantedly, Inc. w HSQDͷಛ௃ w 1SPUPDPM#V⒎FSpMF QSPUPpMF ʹΑΔ TDIFNB؅ཧ

    w CJOBSZGPSNBUͱTFSJBMJ[FEFTFSJBMJ[F ίʔυͷࣗಈੜ੒ w )551Λར༻ͨ͠ޮ཰తͳUSBOTQPSU HSQDͱ͸
  7. ©2018 Wantedly, Inc. w HSQDͷಛ௃ w 1SPUPDPM#V⒎FSpMF QSPUPpMF ʹΑΔ TDIFNB؅ཧ

    w CJOBSZGPSNBUͱTFSJBMJ[FEFTFSJBMJ[F ίʔυͷࣗಈੜ੒ w )551Λར༻ͨ͠ޮ཰తͳUSBOTQPSU HSQDͱ͸
  8. ©2018 Wantedly, Inc. 1SPUPEFGJOJUJPOGJMF QSPUPGJMF ͱ͸ message Person { string

    name = 1; int32 id = 2; string email = 3; } ࢀߟϦϯΫIUUQTEFWFMPQFSTHPPHMFDPNQSPUPDPMCV⒎FST
  9. ©2018 Wantedly, Inc. QSPUPGJMFͰ+40/Λهड़͢Δ message Person { string name =

    1; int32 id = 2; string email = 3; } { "name": "Taro", "id": 13, "email": "[email protected]" } QSPUPpMF +40/
  10. ©2018 Wantedly, Inc. message Person { string name = 1;

    int32 id = 2; string email = 3; } module PersonAttributes extend ActiveSupport::Concern included do attribute :name attribute :id attribute :email end end QSPUPpMF SVCZ QSPUPGJMF͔ΒTFSWFSTJEFͷίʔυੜ੒ w "DUJWF.PEFM4FSJBMJ[FSͷίʔυΛੜ੒
  11. ©2018 Wantedly, Inc. class PersonSerializer < ApplicationSerializer include PersonAttributes end

    QSPUPGJMF͔ΒTFSWFSTJEFͷίʔυੜ੒ w ੜ੒ͨ͠ίʔυΛTFSJBMJ[FS͔Βར༻ class PeopleController < ApplicationController def show @person = Person.find(params[:id]) render json: @person end end
  12. ©2018 Wantedly, Inc. message Person { string name = 1;

    int32 id = 2; string email = 3; } module PersonAttributes extend ActiveSupport::Concern included do attribute :name attribute :id attribute :email end end QSPUPpMF SVCZ QSPUPGJMF͔ΒDMJFOUTJEFͷίʔυੜ੒ w NBQQJOHDMBTTͷίʔυΛੜ੒ʢTFSWFSͱಉ͡
  13. ©2018 Wantedly, Inc. QSPUPGJMF͔ΒDMJFOUTJEFͷίʔυੜ੒ class Models class Person < Base

    include Attributes::PersonAttributes end end w ੜ੒ͨ͠ίʔυΛNBQQJOHDMBTT͔Βར༻ w .PEFMT#BTFͱͯ͠ABUUSJCVUFAΛղऍ͢Δ࣮૷Λ༻ҙ w +40/ΛQBSTFͯ͠ɺσʔλΛอ࣋ɻϝιουͱͯ͠pFMEͷ஋ΛऔΓग़ͤΔ
  14. ©2018 Wantedly, Inc. [1] pry(main)> person = PeopleClient.get(13) I, …

    -- request: GET http://localhost:3000/people/13 . . . => <Models::Person name: “Taro”, id: 13, email: “[email protected]"> [2] pry(main)> personn.name => “Taro"