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

NestJSを活用したREST APIサーバ/REST_API_SERVER_BY_NESTJS

Masahiko Sakakibara
November 29, 2019
1.3k

NestJSを活用したREST APIサーバ/REST_API_SERVER_BY_NESTJS

Masahiko Sakakibara

November 29, 2019
Tweet

More Decks by Masahiko Sakakibara

Transcript

  1. /FTU+4Λ׆༻ͨ͠
    3&45"1*αʔό

    View full-size slide

  2. ࣗݾ঺հ
    !SEMBCP
    Ұൠࣾஂ๏ਓ
    ϦϨʔγϣϯσβΠϯݚڀॴ୅දཧࣄ
    Ұൠࣾஂ๏ਓ
    "SFB*OOPWBUJPO"MJBODF$50
    *POJD+BQBO
    6TFS(SPVQ୅ද

    View full-size slide

  3. ίϯτϦϏϡʔλʔ
    ionic-team/ionic
    ionic-team/starters
    ionic-team/ionic-cli
    ionic-team/ionic-docs
    ionic-team/ionic-react
    -conference-app
    GoogleChrome/lighthouse

    View full-size slide

  4. όοΫΤϯυͱϑϩϯτΤϯυͷͭͳ͗ํ

    View full-size slide

  5. ϨϯμϦϯάίετ͕ॏ͍ಈతαΠτ
    .PEFMͰσʔλΛ੔ܗͯ͠
    ৔߹ʹΑͬͯ͸$PUSPMMFSͰ
    ͦΕΛల։ɾ࠶੔ܗͯ͠
    7JFXͰల։͢Δ

    View full-size slide

  6. ΤϥʔϋϯυϦϯά͕೉͍͠ಈతαΠτ

    View full-size slide

  7. ΑΓΑ͍69Λ໨ࢦͯ͠
    ੩తαΠτ
    4JOHMF1BHF"QQMJDBUJPO 41"

    3&45"1*(SBQI2-ʹΑΔόοΫΤ
    ϯυͱϑϩϯτΤϯυͷϒϦοδ
    +BWB4DSJQUʹΑΔϦονͳ6*
    1SPHSFTTJWF8FC"QQT 18"

    41"8FC"1*
    ಈతαΠτ
    ΑΓΑ͍69Λ໨ࢦ͢

    View full-size slide

  8. +40/Ͱͷ΍ΓͱΓ͕Ұൠతͳख๏ʹɻ
    όοΫΤϯυ
    \n^
    ϑϩϯτΤϯυ
    \n^

    View full-size slide

  9. +40/Ͱൃ࿩͢Δͱ͍͏Ҏ্ͷ৘ใ͸ڞ༗Ͱ͖͍ͯ·͔͢ʁ
    όοΫΤϯυ
    \n^
    ϑϩϯτΤϯυ
    \n^
    ѫࡰͯ͠΄͍͠
    (&5IFMMP
    ʁʁ
    3&45Ͱ͸ɺॲཧํ๏ͱ෼ྨ͔͠ఆٛͯ͘͠Εͳ͍໰୊ɻ

    View full-size slide

  10. ཧ૝ͷੈք
    όοΫΤϯυ
    \n^
    \
    OBNFTUSJOH
    EFTDTUSJOH
    JNBHFTUSJOH
    VSMTUSJOH
    ^<>
    ͰσʔλΛૹΔˠ
    ϑϩϯτΤϯυ
    \n^
    \
    OBNFTUSJOH
    EFTDTUSJOH
    JNBHFTUSJOH
    VSMTUSJOH
    ^<>
    Ͱσʔλ͕ཉ͍͠
    ˡ

    View full-size slide

  11. ͦ͏ͩ5ZQF4DSJQUͩʂ
    w"1*ͷܕΛڞ༗Ͱ͖Δͷ͸5ZQF4DSJQU͚ͩʢ

    wFYQSFTT͸ϑϨʔϜϫʔΫͱͯ͠͸ͪΐͬͱബ͍
    w/FTU+4͸ϑϨʔϜϫʔΫͱͯ͠ͷػೳ͕े෼
    ɾ3&45"1*Λ࠾༻ͯ͠Δ
    ɾৄࡉυΩϡϝϯτͱͷೋॏ؅ཧΛͨ͘͠ͳ͍
    ɹɹɹɹɹɹɹɹɹɹɹɹɹɹɹʜϓϩδΣΫτͰΦεεϝ
    8FC"TTFNCMZͳͲͷಈ࡞؀ڥΛআ͖·͢

    View full-size slide

  12. ܕͷڞ༗ʹ͍ͭͯ

    View full-size slide

  13. ͡Ό͋Ͳ͏΍ͬͯܕΛڞ༗͢Δʁʁ
    όοΫΤϯυ
    \n^
    ϑϩϯτΤϯυ
    \n^
    Ͳ͏΍ͬͯܕΛڞ༗ʁ
    OQNύοέʔδʹ͢Δ ˕ ཧ૝తɻͨͩ͠อक͕खؒɻ
    /FTU+4ͷϓϩδΣΫτʹ
    ஔ͘
    ̋
    ݱ࣮తɻϑϩϯτΤϯυ͔Β͸

    webpackͰόϯυϧ
    ϓϩδΣΫτ֎ʹ͓͘ ˚ tscίϚϯυͷઃఆΛཁมߋʢະௐࠪʣ

    View full-size slide

  14. σϞ
    ʢձ৔ͰͷܕΤϥʔͷ࣮ԋʹͳΓ·͢ʣ

    View full-size slide

  15. XFCQBDLͱUTDίϚϯυ͸ҧ͏
    XFCQBDL
    όϯυϥʔɻUZQFTDSJQUύοέʔδΛར༻͢Δ͜ͱͰɺSFRVJSFؔ਺΍
    JNQPSUؔ਺Λఏڙͯ͠ґଘؔ܎ղܾࡁΈͷγϯϓϧͳϑΝΠϧΛग़ྗ͢Δ
    ͜ͱ͕Ͱ͖Δɻ
    UTDίϚϯυ
    5ZQF4DSJQU͔Β+BWB4DSJQU΁ͷίϯύΠϧΛߦ͏ɻґଘؔ܎ग़ྗͷղܾͳ
    ʹͦΕɻίϯύΠϥͰ͢ɻ

    View full-size slide

  16. CBEQSBDUJDFUPJOTUBMMEFQFOEFODJFTPOBQSPEVDUJPOTFSWFS
    IUUQTHJUIVCDPNHPMECFSHZPOJOPEFCFTUQSBDUJDFTJTTVFT

    View full-size slide

  17. *EPOPUSFDPNNFOEVTJOHBOZCVOEMFSGPS/PEF
    IUUQTHJUIVCDPNOFTUKTOFTUJTTVFTJTTVFDPNNFOU

    View full-size slide

  18. "1*ͳΒ࣌ؒಈ͔͞ͳͯ͘΋͍͍ͷͰ͸
    ʢ4FSWFSͷอकͨ͘͠ͳ͍ʂʣ

    View full-size slide

  19. ৗʹΞΫηε͕͋Δͱ͸ݶΒͳ͍
    load() {
    if (this.data) {
    return of(this.data);
    } else {
    return this.http.get(‘https://example.com‘)

    .pipe(map(this.processData, this));
    }
    }
    ϝϞϦ΍ετϨʔδΛ
    ׆༻ͨ͠Γ
    FϥʔχϯάΈ͍ͨʹ
    සൟͳ"1*ߋ৽͕ͳ͍

    View full-size slide

  20. ͦ͏ͩʂ-BNCEBͩʂʂ
    ʮίʔυͷอकͰखҰഋ͔ͩΒαʔόͷอकͨ͘͠ͳ͍ʯ

    View full-size slide

  21. /PEPDTGSPN
    ʜͭ͘Εͦ͏͡Όͳ͍ʁ

    View full-size slide

  22. ͭ͘Εͨɻ
    ࠓ೔.FFUVQ͋Δ͔Β൒೥ͿΓʹόʔδϣϯ௥ਵͨ͠

    View full-size slide

  23. ࢖͍ํ
    $ npm install serverless -g
    $ git clone [email protected]:rdlabo/serverless-nestjs.git ʲprojectNameʳ
    Πϯετʔϧ
    ։ൃ
    $ npm start
    -BNCEB)PUTUBSUαϙʔτ
    4XBHHFSαϙʔτ
    $ npx ts-node src/swagger.ts

    View full-size slide

  24. ϑϩϯτΤϯυͱόοΫΤϯυͰڞ௨ݴޠΛ
    खʹೖΕΑ͏ɻ
    ϩδΧϧʹָͰ͖Δ/FTU+4͍͍Ͱ͢Α

    View full-size slide

  25. *POJDΛ࢖͏ͱ8FCͰϞόΠϧΞϓϦͭ͘Ε·͢
    ϒϥ΢β 18" J04ΞϓϦ

    View full-size slide

  26. ͜͏͍͏ΞϓϦ͕೔ʹͭ͘ΕΔΑ͏ʹʂ

    View full-size slide

  27. *POJDͰ࡞ΔϞόΠϧΞϓϦ੍࡞ೖ໳
    ୯ߦຊr
    ϖʔδɹ ԁ
    IUUQTBN[OUP1"S&M

    View full-size slide