Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
RubyͷJSONγϦΞϥΠβΛ ൺֱͯ͠Έͨ2020൛ Gotanda.rb#44 2020-07-22 ©େխ࢙
Slide 2
Slide 2 text
ࣗݾհ • ໊લɿେխ࢙ • ॴଐɿϑϦʔϥϯεʢྺ1ͪΐͬͱɺRubyࣗମ8΄Ͳʣ • ΤσΟλɿNeovimʢVimྺ8΄Ͳʣ • ͖ͳϝιουɿinstance_exec • झຯɿᘖᘣ☕
Slide 3
Slide 3 text
ࣗݾհʢଓ͖ʣ • Kaigi on RailsͷνʔϑΦʔΨφΠβʔΛ͍ͯ͠·͢ • CFPࠓ݄·ͰͳͷͰ͢ωλ͕͋Δํͥͻʂ • ʰϚελϦϯάVimʱͷ༁Λ͠·ͨ͠ • Grow.rbͱEntaku.rbͱ͍͏ίϛϡχςΟΛιϩͰӡӦ͍ͯ͠·͢ • Shibuya.rbͱTama.rbͷڞಉΦʔΨφΠβʔͰ͋Γ·͢
Slide 4
Slide 4 text
ࠓͷςʔϚɿ API/JSONʹ͍ͭͯ
Slide 5
Slide 5 text
RubyΛͬͯJSONΛฦ͢ํ๏
Slide 6
Slide 6 text
JSONγϦΞϥΠβ
Slide 7
Slide 7 text
ϝδϟʔͲ͜ΖΛൺֱͯ͠Έͨ
Slide 8
Slide 8 text
JSONγϦΞϥΠβ3ܼʢେௐʣ • ActiveModelSerializersʢҎԼAMSʣ • ελʔ5kɺ • jbuilder • ελʔ3.8kɺRailsͷσϑΥϧτʹؚ·ΕΔɺ • fast_jsonapi • ελʔ5k
Slide 9
Slide 9 text
ͦͷଞͷJSONγϦΞϥΠβ • jsonapi-rb • jsonapi-resources • blueprinter • jb • representable • jsonapi-serializer
Slide 10
Slide 10 text
AMS • ݹࢀͷJSONγϦΞϥΠβ • Pros • ྺ࢙͕͘ɺWebʹهࣄ͕๛ʹ͋Δ • ͲΜͳJSONεΩʔϚʹରԠՄೳ • Cons • ΄΅ϝϯς͞Ε͍ͯͳ͍༷ࢠ • ʹ͕͋Δʢಛʹfast_jsonapiͱͷൺֱͰʣ
Slide 11
Slide 11 text
jbuilder • Railsͷ४ެࣜJSONγϦΞϥΠβ • Pros • RailsͷίΞνʔϜʹϝϯς͞Ε͍ͯΔ҆৺ײ • RailsͰ͏ͳΒґଘؔΛ૿ͣ͞ʹࡁΉ • Cons • ͍ɺ͔ͳΓ͍ • ه๏ʢDSLʣ͕ಠಛͰशಘ͕େม
Slide 12
Slide 12 text
fast_jsonapi • Netflix͕ग़ͨ͠JSON:APIಛԽܕͷJSONγϦΞϥΠβ • Pros • ඇৗʹߴ • Cons • JSON:APIʹ४ڌͨ͠APIʹͨ͑͠ͳ͍ • Netflix͕ϝϯςΛ์غ͠ɺ༗ࢤͷϑΥʔΫ͕ଘࡏ͢Δ͕gemͷ໊લ͕ มΘ͍ͬͯͨΓͯࠞ͠ಱͱ͍ͯ͠Δ
Slide 13
Slide 13 text
".4 KCVJMEFS GBTU@KTPOBQJ ύϑΥʔϚϯε ͦͦ͜͜ ѱ͍ ඇৗʹྑ͍ ϝϯςφϯε ͞Ε͍ͯͳ͍ ͞Ε͍ͯΔ ͞Ε͍ͯͳ͍ ҙͷ+40/εΩʔ ϚʹରԠ͍ͯ͠Δ ͍Δ ͍Δ ͍ͳ͍
Slide 14
Slide 14 text
͜͜·Ͱͷ݁
Slide 15
Slide 15 text
• ߴ • ϝϯς͞Ε͍ͯΔ • ҙͷεΩʔϚͷJSON͕ग़ྗͰ͖ ΔʢJSON:APIܗࣜҎ֎ʹରԠ͠ ͍ͯΔʣ
Slide 16
Slide 16 text
ͳ͍ʁ
Slide 17
Slide 17 text
͓Εͷ͔Μ͕͍͖͑ͨ͞ΐ͏ ͷJSONγϦΞϥΠβɺAlba ͷ͝հ Gotanda.rb#44 2020-07-22 ©େխ࢙
Slide 18
Slide 18 text
• ߴ • ϝϯς͞Ε͍ͯΔ • ҙͷεΩʔϚͷJSON͕ग़ྗͰ͖ ΔʢJSON:APIܗࣜҎ֎ʹରԠ͠ ͍ͯΔʣ
Slide 19
Slide 19 text
ػೳΛߜΔ
Slide 20
Slide 20 text
ࢦ͖ͩ͢ͱࢥ͏ͷ
Slide 21
Slide 21 text
• ΑΓখ͞ͳίΞ • ΑΓগͳ͍DSL • ΑΓগͳ͍ґଘؔ
Slide 22
Slide 22 text
ΑΓখ͍͞ίΞ • ShrineʢϑΝΠϧΞοϓϩʔυϥΠϒϥϦʣRodaʢܰྔΣϒΞ ϓϦέʔγϣϯϑϨʔϜϫʔΫʣͷΑ͏ͳϓϥάΠϯϕʔεͷߏʹ ಌΕ͍ͯΔ • ࢦ͢ίΞͷResourceϞδϡʔϧΛ100ߦҎԼʹཹΊΔ͜ͱ • ֎෦͔Β֦ுՄೳʹ͍ͨ͠ • ίΞͷϝϯςΛָʹ͍ͨ͠
Slide 23
Slide 23 text
ΑΓগͳ͍DSL • attribute, one, many͘Β͍Ͱे͔ͳͱࢥ͍ͬͯΔ • jbuilderͷDSL͕͔ͳΓۤखͱ͍͏ݸਓతͳؾ࣋ͪ • has_manyΛΑ͘ݟ͔͚Δ͚ͲɺRuboCopʹޡղ͞ΕͨΓ͢Δ͋͠· Γ͍͍ΞΠσΞͰͳ͍Α͏ͳ…
Slide 24
Slide 24 text
ΑΓগͳ͍ґଘؔ • ҙݻʹͳͬͯActiveSupportͷґଘΛՃ͍ͯ͠ͳ͍ • ͦͷ݁Ռͱͯ͠Inflection͕͑ͳͯͭ͘Β͍ • ͦͦʮΦϒδΣΫτΛJSONʹม͢Δʯ͜ͱʹґଘ͕ؔͨ͘ ͞Μඞཁͬͯ͜ͱͳ͍ͷͰɺͱ͍͏ؾ࣋ͪ • ϝϯςָ͕ • ґଘ͕ؔͳ͍gemͷಌΕ
Slide 25
Slide 25 text
͕࣌ؒ͋ΕιʔείʔυΛ͔ΜͨΜ ʹ͓ݟͤͰ͖Δ͔ͳ