Save 37% off PRO during our Black Friday Sale! »

Modern REST Communicate for Android

Modern REST Communicate for Android

社内発表用スライド

E8e0607f1d935e9595375e04498f223a?s=128

kobayashi_kento

May 23, 2016
Tweet

Transcript

  1. Modern REST Communicate for Android 2016.5.20 @kobaken42

  2. Agenda • Keyword • ΍Βͳ͍͜ͱ • RESTʹ͍ͭͯ • ࢖༻ϥΠϒϥϦ঺հ •

    αϯϓϧΞϓϦͷ࣮૷(ϨϏϡϫʔ͋Γ) • Keyword(͓͞Β͍)
  3. Keyword • REST(RESTful) • (ؔ਺ܕ)ϦΞΫςΟϒϓϩάϥϛϯά(FRP) • ReactiveX(ϦΞΫςΟϒΤΫεςϯγϣϯ) • Parse(ύʔε)

  4. ΍Βͳ͍͜ͱ • Androidʹؔ͢Δઆ໌(Activity, Fragment, Lifecycle etc…) • RESTɺFRPʹؔ͢Δৄࡉͳઆ໌ • ϨΨγʔͳ࣮૷ͱͷൺֱ

  5. ʊਓਓਓਓʊ ʼ REST ʻ ʉY^Y^Y^Yʉ

  6. Webͷ ΞʔΩςΫνϟελΠϧͷҰͭ

  7. ύϥϝʔλΛࢦఆͯ͠ ಛఆURLʹHTTP(s)ͰΞΫηε XML or jsonͰ݁Ռ͕ฦ٫͞ΕΔ

  8. ύϥϝʔλ(Input)͕ಉҰͳΒ ৗʹಉ݁͡Ռ(Output)͕ظ଴Ͱ͖Δ (γεςϜͷঢ়ଶ΍ηογϣϯʹґଘ͠ͳ͍)

  9. (ͪΐͬͱཚ๫͚ͩͲ) ҰߦͰݴ͏ͱ

  10. Ϧιʔεॏࢹઃܭ

  11. RESTful item_url -> items/:id new_item_url -> items/new edit_item_url -> items/:id/edit

    items_url -> items
  12. Not RESTful

  13. ίϨͰΘ͔Βͳ͍ਓ͸ ϫγϫγMAX΍Ͱʙʂʂ ͦΜͳͷ͋Μ·Γʹ͜ʙʂʂ

  14. ຊ୊΁

  15. ϦΞΫςΟϒͳ REST௨৴Λ࣮ݱͨ͠ αϯϓϧΞϓϦΛ࡞੒͍͖ͯ͠·͢

  16. ༏लͳϨϏϡϫʔͷྗΛ आΓͳ͕Β࣮૷͍͖ͯ͠·͢Αʂ

  17. ࢖༻ϥΠϒϥϦͷ঺հ

  18. ࢖༻ϥΠϒϥϦ(Plugin) • Retrofit • RxAndroid • Retrolambda • Lombok •

    butterknife(DataBindingʹஔ͖׵͑·ͨ͠)
  19. Retrofit v2.0.2 • AndroidͱJavaͷͨΊͷܕ҆શͳ HTTPΫϥΠΞϯτ • ಺෦ͰOkhttpΛ࢖༻ • AsyncLoaderͱ͸΋͏͓͞Β͹ •

    jsonύʔεͱ͔ॾʑ΍ͬͯ͘ΕΔ • Apache HTTP ClientʁūŬťƀŘŶƂŜƃūŘ!!
  20. RxAndroid v1.2.0 • RxJavaΛ಺แ͍ͯ͠ΔAndroid޲͚ ReactiveX • ϦΞΫςΟϒϓϩάϥϛϯάग़དྷΔ • ඇಉظॲཧ͕؆୯ʹॻ͚Δ (AsyncTaskͳΜͯͳ͔ͬͨ)

    • ڞ௨ͷΠϯλʔϑΣʔεͱͯ͠׆༻ • View͔ΒͷΠϕϯτΛड͚औΔ • ίʔϧόοΫͷҰݩ؅ཧ etc…
  21. Retrolambda • AndroidͰϥϜμ͕ࣜॻ͚ΔΑ͏ʹ ͳΔPlugin • Method Referenceʹ΋ରԠ • RxAndroid, Stream

    APIͱͷซ༻ར ༻Ͱ΄΅Java8؀ڥʹʂ
  22. Lombok v1.16.8 • JavaͰΑ͋͘ΔϘΠϥʔϓϨʔτ ίʔυΛγϯϓϧʹͯ͘͠ΕΔ • getter, setterͷهड़ෆཁʹ • nullνΣοΫΛࣗಈͰ΍ͬͯ͘ΕΔ

    • MITϥΠηϯε
  23. ϥΠϒϥϦ঺հ͸͜͜·Ͱ

  24. ΍Δ͜ͱ

  25. ΍Δ͜ͱ • ࢖༻ϥΠϒϥϦΛGradleͰએݴ • REST௨৴ͷͨΊͷAPIΠϯλʔϑΣʔε࡞੒ • Ϩεϙϯε༻ͷΦϒδΣΫτΛ࡞੒ • ϦΞΫςΟϒϓϩάϥϛϯάͰREST௨৴ʂ

  26. Ͱ͸ૣ଎

  27. gradleʹهड़ͯ͘͠Ͱ

  28. build.gradle(app௚Լ)

  29. None
  30. None
  31. WebAPIͷInterface ࡞ΔͰ

  32. ࠓճ͸ొ࿥ෆཁͳ͓खܰAPIΛ ར༻͍ͨ͠Μ΍ʂ

  33. ࢖༻API • WeatherHacks

  34. WeatherHacksApi.java

  35. None
  36. None
  37. ResponseObject(Entity) ࡞ΔͰ

  38. ResponseObject.java

  39. None
  40. None
  41. Լ४උऴΘΓ

  42. ͦΕ͡Όɺຊ൪ߦ͘΍Ͱ

  43. ͜Ε͔Β΍Δ͜ͱ

  44. ࡾߦͰ

  45. Activity(Fragment)ʹ RetrofitΦϒδΣΫτΛੜ੒ͯ͠ subscribeʂ

  46. MainActivity.java

  47. MainActivity.java

  48. MainActivity.java

  49. ͜Ε͚ͩʂ

  50. ͱ

  51. ࢥΘͤͯ

  52. AndroidManifest.xmlʹ Internet௨৴ͷͨΊͷ Permissionهड़͕ඞཁͦ͏ɾɾɾ

  53. None
  54. AndroidManifest.xml

  55. AndroidManifest.xml

  56. None
  57. Keyword(͓͞Β͍) • REST(RESTful) • (ؔ਺ܕ)ϦΞΫςΟϒϓϩάϥϛϯά(FRP) • ReactiveX(ϦΞΫςΟϒΤΫεςϯγϣϯ) • Parse(ύʔε) •

    ঁਆͷΜͨΜ
  58. ΈΜͳ΋ϦΞΫςΟϒʹ REST௨৴͠Αͬˑ

  59. None
  60. https://github.com/kobaken0029/RestSample