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

͕࣌ؒ͋Ε͹ιʔείʔυΛ͔ΜͨΜ ʹ͓ݟͤͰ͖Δ͔ͳ