9-2:トークン、fetch、debugger



  • [サーバ]トークンベースの認証VSサーバベースの認証

  • Access Token & Refresh Token

  • Fetch関数サンプルコード
  • export class AdminUserService {
      static createAdminUser = (params) => {
        let apiPath = `${API_BASE_URL}/admin-users`;
    
        return fetch(apiPath, {
          method: "POST",
          body: JSON.stringify(params),
          headers: HttpUtil.getHeader(),
        })
          .then(HttpUtil.handleHttpStatus)
          .catch(HttpUtil.handleHttpStatusError)
          .then((res) => res.json());
      };
    post方式で伝達するときのコード.body必要なデータは対象として整理し、JSON.stringify()関数でstringに変換する.("{"key": "value", "key2": "value2", ...}.catch()文はfetch()のみならず.then()でもエラーが実行される.
  • debugger使い方
  • console.logと似ていますが、いちいち撮影する必要はなく、データを一度に表示します.