{"id":1861,"date":"2025-11-23T10:43:28","date_gmt":"2025-11-23T01:43:28","guid":{"rendered":"https:\/\/route-zero.com\/recruit\/?post_type=route&#038;p=1861"},"modified":"2026-01-23T10:43:54","modified_gmt":"2026-01-23T01:43:54","slug":"axios%e3%81%a8fetch%e3%81%a9%e3%81%a3%e3%81%a1%e3%82%92%e9%81%b8%e3%81%b6%ef%bc%9fapi%e9%80%a3%e6%90%ba%e3%81%a7%e5%a4%b1%e6%95%97%e3%81%97%e3%81%aa%e3%81%84%e9%81%b8%e5%ae%9a%e3%83%95%e3%83%ad","status":"publish","type":"route","link":"https:\/\/route-zero.com\/recruit\/route\/1861\/","title":{"rendered":"axios\u3068fetch\u3069\u3063\u3061\u3092\u9078\u3076\uff1fAPI\u9023\u643a\u3067\u5931\u6557\u3057\u306a\u3044\u9078\u5b9a\u30d5\u30ed\u30fc\u3068\u5b9f\u8df5\u30b3\u30fc\u30c9"},"content":{"rendered":"<div>\n<h1>axios\u3068fetch\u3001\u3069\u3063\u3061\u3092\u9078\u3076\uff1f\u73fe\u5834\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u5fb9\u5e95\u6bd4\u8f03\u30ac\u30a4\u30c9<\/h1>\n<p>\n    \u300c<strong>React<\/strong>\u3084<strong>TypeScript<\/strong>\u3067API\u9023\u643a\u3057\u3066\u3044\u308b\u3068\u3001<strong>fetch\u306e\u30b3\u30fc\u30c9\u304c\u3084\u305f\u3089\u9577\u304f\u306a\u308b\u2026<\/strong>\u305d\u3093\u306a\u7d4c\u9a13\u306f\u3042\u308a\u307e\u305b\u3093\u304b\uff1f\u300d<br \/>\n    \u79c1\u305f\u3061\u304c\u65e5\u3005\u5411\u304d\u5408\u3046<strong>API\u5b9f\u88c5<\/strong>\u3002\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3067\u6bce\u56de\u60a9\u3093\u3060\u308a\u3001\u300c\u672c\u5f53\u306b\u3053\u306e\u66f8\u304d\u65b9\u304c\u30d9\u30b9\u30c8\u306a\u306e\u304b\uff1f\u300d\u3068\u8ff7\u3046\u3053\u3068\u3082\u591a\u3044\u3067\u3059\u3088\u306d\u3002<br \/>\n    \u7279\u306b<strong>4xx\/5xx\u30a8\u30e9\u30fc<\/strong>\u3084<strong>TypeScript\u306e\u578b\u4ed8\u3051<\/strong>\u306b\u201c\u3082\u3084\u3082\u3084\u201d\u3057\u304c\u3061\u2015\u2015\u3002<br \/>\n    \u30b3\u30fc\u30c9\u30ec\u30d3\u30e5\u30fc\u3067\u300c<strong>axios\u4f7f\u3048\u3070\u7c21\u6f54\u3060\u3088<\/strong>\u300d\u3068\u5148\u8f29\u306b\u8a00\u308f\u308c\u305f\u3082\u306e\u306e\u3001<br \/>\n    \u300c<strong>\u4f9d\u5b58\u3092\u5897\u3084\u3059\u30ea\u30b9\u30af\u3092\u53d6\u3063\u3066\u307e\u3067\u5c0e\u5165\u3059\u308b\u4fa1\u5024\u306f\u3042\u308b\uff1f<\/strong>\u300d\u3068\u5224\u65ad\u306b\u8ff7\u3046\u65b9\u3082\u591a\u3044\u306f\u305a\u3067\u3059\u3002\n  <\/p>\n<p>\n    \uff08TypeScript\u306e\u57fa\u790e\u3084\u578b\u4ed8\u3051\u306b\u3064\u3044\u3066\u306f\u300e<a href=\"https:\/\/route-zero.com\/recruit\/route\/1279\" target=\"_blank\" rel=\"noopener\">TypeScript\u3068\u306f\uff1fJavaScript\u3068\u306e\u9055\u3044\u3092\u521d\u5fc3\u8005\u5411\u3051\u306b\u308f\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac<\/a\n    >\u300f\u3092\u3054\u53c2\u7167\u304f\u3060\u3055\u3044\uff09\n  <\/p>\n<blockquote>\n<p><strong>\u7528\u8a9e\u89e3\u8aac\uff1aReact<\/strong><br \/>Facebook\u304c\u958b\u767a\u3057\u305fUI\u69cb\u7bc9\u7528JavaScript\u30e9\u30a4\u30d6\u30e9\u30ea\u3002\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5358\u4f4d\u3067Web\u30a2\u30d7\u30ea\u3092\u52b9\u7387\u7684\u306b\u4f5c\u308c\u308b\u3002<\/p>\n<p><strong>\u7528\u8a9e\u89e3\u8aac\uff1aTypeScript<\/strong><br \/>JavaScript\u306b\u578b\u4ed8\u3051\u6a5f\u80fd\u3092\u52a0\u3048\u305f\u8a00\u8a9e\u3002\u578b\u5b89\u5168\u6027\u304c\u9ad8\u304f\u3001\u5927\u898f\u6a21\u958b\u767a\u3084\u4fdd\u5b88\u306b\u5f37\u3044\u3002<\/p>\n<p><strong>\u7528\u8a9e\u89e3\u8aac\uff1aAPI<\/strong><br \/>\u30a2\u30d7\u30ea\u3084\u30b5\u30fc\u30d3\u30b9\u540c\u58eb\u304c\u30c7\u30fc\u30bf\u3084\u6a5f\u80fd\u3092\u3084\u308a\u53d6\u308a\u3059\u308b\u305f\u3081\u306e\u300c\u7a93\u53e3\u300d\u3068\u306a\u308b\u4ed5\u7d44\u307f\u3002<\/p>\n<p><strong>\u7528\u8a9e\u89e3\u8aac\uff1a\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0<\/strong><br \/>\u30d7\u30ed\u30b0\u30e9\u30e0\u5b9f\u884c\u4e2d\u306e\u30a8\u30e9\u30fc\u767a\u751f\u6642\u306b\u3001\u9069\u5207\u306a\u51e6\u7406\u3084\u901a\u77e5\u3092\u884c\u3046\u4ed5\u7d44\u307f\u3002<\/p>\n<p><strong>\u7528\u8a9e\u89e3\u8aac\uff1a4xx\/5xx\u30a8\u30e9\u30fc<\/strong><br \/>HTTP\u901a\u4fe1\u3067\u767a\u751f\u3059\u308b\u30a8\u30e9\u30fc\u30024xx\u306f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u30015xx\u306f\u30b5\u30fc\u30d0\u30fc\u5074\u306e\u554f\u984c\u3092\u793a\u3059\u3002<\/p>\n<p><strong>\u7528\u8a9e\u89e3\u8aac\uff1a\u4f9d\u5b58\u30e9\u30a4\u30d6\u30e9\u30ea<\/strong><br \/>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u5229\u7528\u3059\u308b\u5916\u90e8\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u7fa4\u3002\u5c0e\u5165\u6570\u304c\u5897\u3048\u308b\u3068\u7ba1\u7406\u3084\u30d0\u30f3\u30c9\u30eb\u30b5\u30a4\u30ba\u306b\u5f71\u97ff\u3002<\/p>\n<\/blockquote>\n<hr \/>\n<h2>\u307e\u305a\u7d50\u8ad6\uff1aaxios vs fetch \u6bd4\u8f03\u65e9\u898b\u8868<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u6a5f\u80fd\u30fb\u89b3\u70b9<\/th>\n<th>axios<\/th>\n<th>fetch API<\/th>\n<th>\u8a55\u4fa1\u30fb\u30b3\u30e1\u30f3\u30c8<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>\u69cb\u6587\u306e\u7c21\u6f54\u3055<\/strong><\/td>\n<td>\u25ce<\/td>\n<td>\u25b3<\/td>\n<td>axios\u306f1\u30b9\u30c6\u30c3\u30d7\u3067JSON\u53d6\u5f97\u3002fetch\u306f2\u6bb5\u968e\u51e6\u7406\u304c\u5fc5\u8981\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>\u30a8\u30e9\u30fc\u51e6\u7406\u306e\u76f4\u611f\u6027<\/strong><\/td>\n<td>\u25ce<\/td>\n<td>\u2715<\/td>\n<td>axios\u306fHTTP\u30a8\u30e9\u30fc\u3082\u81ea\u52d5\u3067catch\u53ef\u80fd\u3002fetch\u306fres.ok\u5fc5\u9808\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>TypeScript\u3068\u306e\u89aa\u548c\u6027<\/strong><\/td>\n<td>\u25cb<\/td>\n<td>\u25b3<\/td>\n<td>axios\u306f\u30b8\u30a7\u30cd\u30ea\u30af\u30b9\u3067\u578b\u4ed8\u3051\u304c\u697d\u3002fetch\u306f\u30a2\u30b5\u30fc\u30b7\u30e7\u30f3\u591a\u767a\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\/\u4e2d\u65ad<\/strong><\/td>\n<td>\u25ce<\/td>\n<td>\u25cb<\/td>\n<td>axios\u306ftimeout\u6307\u5b9a\u3060\u3051\u3002fetch\u306fAbortController\u5b9f\u88c5\u304c\u5fc5\u8981\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>\u5171\u901a\u51e6\u7406\u306e\u62bd\u8c61\u5316<\/strong><\/td>\n<td>\u25ce<\/td>\n<td>\u2715<\/td>\n<td>axios\u306f\u30a4\u30f3\u30bf\u30fc\u30bb\u30d7\u30bf\u30fc\u3067\u5171\u901a\u51e6\u7406\u3092\u4e00\u5143\u5316\u3067\u304d\u308b\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>\u63d0\u4f9b\u5143<\/strong><\/td>\n<td>\u30e9\u30a4\u30d6\u30e9\u30ea<\/td>\n<td>\u30d6\u30e9\u30a6\u30b6\u6a19\u6e96<\/td>\n<td>axios\u306f\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u8981\u3002fetch\u306f\u5373\u5229\u7528\u53ef\u80fd\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>\u30d0\u30f3\u30c9\u30eb\u30b5\u30a4\u30ba<\/strong><\/td>\n<td>\u25b3\uff08\u7d0411KB\u5897\uff09<\/td>\n<td>\u25ce\uff08\u8ffd\u52a0\u30bc\u30ed\uff09<\/td>\n<td>\u591a\u6a5f\u80fd\u3068\u306e\u30c8\u30ec\u30fc\u30c9\u30aa\u30d5\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u30dd\u30a4\u30f3\u30c8\uff1a<\/strong>axios\u306ffetch\u306e\u7169\u96d1\u3055\u3092\u958b\u767a\u8005\u30d5\u30ec\u30f3\u30c9\u30ea\u30fc\u306b\u30e9\u30c3\u30d7\u3002\u7279\u306b<strong>\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0<\/strong>\u3068<strong>\u5171\u901a\u51e6\u7406<\/strong>\u3067\u5927\u304d\u306a\u5dee\u304c\u51fa\u307e\u3059\u3002<\/p>\n<blockquote>\n<p><strong>\u7528\u8a9e\u89e3\u8aac\uff1afetch<\/strong><br \/>\u30d6\u30e9\u30a6\u30b6\u6a19\u6e96\u306eHTTP\u901a\u4fe1API\u3002\u8ffd\u52a0\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u4e0d\u8981\u3067\u8efd\u91cf\u3060\u304c\u3001\u30a8\u30e9\u30fc\u51e6\u7406\u3084\u62e1\u5f35\u6027\u306f\u3084\u3084\u9650\u5b9a\u7684\u3002<\/p>\n<p><strong>\u7528\u8a9e\u89e3\u8aac\uff1aaxios<\/strong><br \/>JavaScript\/TypeScript\u5411\u3051\u306e\u4eba\u6c17HTTP\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30e9\u30a4\u30d6\u30e9\u30ea\u3002\u76f4\u611f\u7684\u306a\u69cb\u6587\u3068\u591a\u6a5f\u80fd\u304c\u7279\u9577\u3002<\/p>\n<p><strong>\u7528\u8a9e\u89e3\u8aac\uff1a\u30a4\u30f3\u30bf\u30fc\u30bb\u30d7\u30bf\u30fc<\/strong><br \/>\u30ea\u30af\u30a8\u30b9\u30c8\u3084\u30ec\u30b9\u30dd\u30f3\u30b9\u306e\u5171\u901a\u51e6\u7406\u3092\u81ea\u52d5\u3067\u633f\u5165\u3067\u304d\u308b\u4ed5\u7d44\u307f\u3002\u8a8d\u8a3c\u3084\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u306e\u4e00\u5143\u5316\u306b\u4fbf\u5229\u3002<\/p>\n<p><strong>\u7528\u8a9e\u89e3\u8aac\uff1a\u30d0\u30f3\u30c9\u30eb\u30b5\u30a4\u30ba<\/strong><br \/>Web\u30a2\u30d7\u30ea\u306b\u542b\u307e\u308c\u308b\u5168\u30d5\u30a1\u30a4\u30eb\u306e\u5408\u8a08\u5bb9\u91cf\u3002\u5927\u304d\u3044\u3068\u521d\u56de\u8868\u793a\u304c\u9045\u304f\u306a\u308b\u3002<\/p>\n<\/blockquote>\n<hr \/>\n<h2>1\u5206\u8a3a\u65ad\uff1a\u3042\u306a\u305f\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306baxios\u306f\u5fc5\u8981\uff1f<\/h2>\n<h3>Q1. \u5916\u90e8\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u4f9d\u5b58\u306f\u6700\u5c0f\u306b\u3057\u305f\u3044\uff1f<\/h3>\n<ul>\n<li><strong>YES \u2192 fetch\u63a8\u5968<\/strong>\uff08\u6a19\u6e96API\u3067\u8efd\u91cf\u3002\u30a8\u30e9\u30fc\u51e6\u7406\u306e\u5197\u9577\u3055\u306f\u8a31\u5bb9\u3059\u308b\u5fc5\u8981\u3042\u308a\uff09<\/li>\n<li><strong>NO \u2192 Q2\u3078<\/strong><\/li>\n<\/ul>\n<h3>Q2. 4xx\/5xx\u7cfb\u30a8\u30e9\u30fc\u3092\u5171\u901a\u3067\u30b7\u30f3\u30d7\u30eb\u306b\u51e6\u7406\u3057\u305f\u3044\uff1f<\/h3>\n<ul>\n<li><strong>YES \u2192 axios\u5f37\u304f\u63a8\u5968<\/strong>\uff08HTTP\u30a8\u30e9\u30fc\u3082catch\u3067\u304d\u308b\u305f\u3081\u30d0\u30b0\u9632\u6b62\u306b\u6709\u52b9\uff09<\/li>\n<li><strong>NO \u2192 Q3\u3078<\/strong><\/li>\n<\/ul>\n<h3>Q3. \u8a8d\u8a3c\u30c8\u30fc\u30af\u30f3\u4ed8\u4e0e\u306a\u3069\u5171\u901a\u51e6\u7406\u3092\u307e\u3068\u3081\u305f\u3044\uff1f<\/h3>\n<ul>\n<li><strong>YES \u2192 axios\u5f37\u304f\u63a8\u5968<\/strong>\uff08\u30a4\u30f3\u30bf\u30fc\u30bb\u30d7\u30bf\u30fc\u3067\u4e00\u62ec\u7ba1\u7406\u3067\u304d\u308b\uff09<\/li>\n<li><strong>NO \u2192 fetch\u3067\u3082\u53ef<\/strong>\uff08GET\u4e2d\u5fc3\u3084\u5171\u901a\u51e6\u7406\u4e0d\u8981\u306a\u3089\u5341\u5206\uff09<\/li>\n<\/ul>\n<p><strong>\u8a3a\u65ad\u7d50\u679c\uff1a<\/strong>\u30a8\u30e9\u30fc\u51e6\u7406\u30fb\u5171\u901a\u51e6\u7406\u3067\u8ff7\u3046\u306a\u3089axios\u304c\u6709\u5229\u3002\u5358\u7d14\u306a\u30ea\u30af\u30a8\u30b9\u30c8\u3060\u3051\u306a\u3089fetch\u3067OK\u3002<\/p>\n<hr \/>\n<h2>5\u3064\u306e\u5b9f\u8df5\u30b3\u30fc\u30c9\u3067\u7406\u89e3\u3059\u308b\uff1aaxios\u3068fetch\u306e\u9055\u3044<\/h2>\n<h3>1. \u69cb\u6587\u306e\u7c21\u6f54\u3055 \u2015 \u57fa\u672c\u306eGET\u30ea\u30af\u30a8\u30b9\u30c8<\/h3>\n<h4>fetch\u306e\u5834\u5408<\/h4>\n<pre><code>import { useState, useEffect } from 'react';\r\ntype User = { id: number; name: string; };\r\n\r\nconst UserProfileWithFetch = () =&gt; {\r\n  const [user, setUser] = useState&lt;User | null&gt;(null);\r\n\r\n  useEffect(() =&gt; {\r\n    fetch('https:\/\/api.example.com\/user\/1')\r\n      .then(res =&gt; {\r\n        if (!res.ok) throw new Error('Network response was not ok');\r\n        return res.json();\r\n      })\r\n      .then(data =&gt; setUser(data))\r\n      .catch(err =&gt; console.error('Fetch error:', err));\r\n  }, []);\r\n};<\/code><\/pre>\n<h4>axios\u306e\u5834\u5408<\/h4>\n<pre><code>import { useState, useEffect } from 'react';\r\nimport axios from 'axios';\r\ntype User = { id: number; name: string; };\r\n\r\nconst UserProfileWithAxios = () =&gt; {\r\n  const [user, setUser] = useState&lt;User | null&gt;(null);\r\n\r\n  useEffect(() =&gt; {\r\n    axios.get&lt;User&gt;('https:\/\/api.example.com\/user\/1')\r\n      .then(res =&gt; setUser(res.data))\r\n      .catch(err =&gt; console.error('Axios error:', err));\r\n  }, []);\r\n};<\/code><\/pre>\n<p><strong>\u89e3\u8aac\uff1a<\/strong>fetch\u306f\u30a8\u30e9\u30fc\u30c1\u30a7\u30c3\u30af\uff0bJSON\u5909\u63db\u306e2\u30b9\u30c6\u30c3\u30d7\u3002axios\u306f\u30ef\u30f3\u30b9\u30c6\u30c3\u30d7\u3002<\/p>\n<p>\n    \uff08API\u306e\u57fa\u790e\u3084\u73fe\u5834\u3067\u306e\u4f7f\u3044\u65b9\u306b\u3064\u3044\u3066\u306f\u300e<a href=\"https:\/\/route-zero.com\/recruit\/route\/1759\" target=\"_blank\" rel=\"noopener\">API\u3068\u306f\uff1fSES\u73fe\u5834\u3067\u5f79\u7acb\u3064\u57fa\u790e\u301cPostman\u6d3b\u7528\u307e\u3067\u5b8c\u5168\u30ac\u30a4\u30c9<\/a\n    >\u300f\u3092\u3054\u53c2\u7167\u304f\u3060\u3055\u3044\uff09\n  <\/p>\n<hr \/>\n<h3>2. \u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0 \u2015 \u201cres.ok\u201d\u4e0d\u8981\uff01\u7d71\u4e00catch\u306e\u5b89\u5fc3\u611f<\/h3>\n<ul>\n<li>fetch\u306f\u300c\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a8\u30e9\u30fc\u306e\u307f\u300dcatch\u5bfe\u8c61\u3002404\/500\u7b49\u306eHTTP\u30a8\u30e9\u30fc\u306f<strong>\u660e\u793a\u7684\u306a\u30c1\u30a7\u30c3\u30af\u5fc5\u9808<\/strong>\u3002<\/li>\n<li>axios\u306f<strong>4xx\/5xx\u3082catch\u3067\u62fe\u3048\u308b<\/strong>\u305f\u3081\u3001\u30d0\u30b0\u306e\u6e29\u5e8a\u304c\u6e1b\u308a\u307e\u3059\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>3. TypeScript\u3068\u306e\u9023\u643a \u2015 \u578b\u5b89\u5168\u3082axios\u304c\u4e00\u6b69\u4e0a<\/h3>\n<p>\n    <strong>fetch\uff1a<\/strong>\n  <\/p>\n<pre><code>fetch(...).then(res =&gt; res.json()).then(data =&gt; setUser(data as User));<\/code><\/pre>\n<p>  <strong>axios\uff1a<\/strong><\/p>\n<pre><code>axios.get&lt;User&gt;('...').then(res =&gt; setUser(res.data));<\/code><\/pre>\n<p><strong>\u89e3\u8aac\uff1a<\/strong>axios\u306f<strong>\u30b8\u30a7\u30cd\u30ea\u30af\u30b9\u578b<\/strong>\u3067\u578b\u5b89\u5168\uff06\u7701\u30b3\u30fc\u30c9\u3002<\/p>\n<blockquote>\n<p><strong>\u7528\u8a9e\u89e3\u8aac\uff1a\u30b8\u30a7\u30cd\u30ea\u30af\u30b9<\/strong><br \/>\u578b\u3092\u30d1\u30e9\u30e1\u30fc\u30bf\u5316\u3057\u3001\u67d4\u8edf\u304b\u3064\u578b\u5b89\u5168\u306b\u95a2\u6570\u3084\u30af\u30e9\u30b9\u3092\u6271\u3048\u308bTypeScript\u306e\u6a5f\u80fd\u3002<\/p>\n<\/blockquote>\n<hr \/>\n<h3>4. \u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u30fb\u4e2d\u65ad\u51e6\u7406 \u2015 \u30b7\u30f3\u30d7\u30eb\u306aaxios\u3001\u3084\u3084\u8907\u96d1\u306afetch<\/h3>\n<ul>\n<li>fetch\uff1aAbortController\u3067\u4e2d\u65ad\u7ba1\u7406\u3002\u6bce\u56de\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u751f\u6210\uff06\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\u8981\u3002<\/li>\n<li>axios\uff1atimeout\u6307\u5b9a\u3060\u3051\u3067OK\uff08\u4e2d\u65ad\u3082\u30b5\u30dd\u30fc\u30c8\uff09\u3002<\/li>\n<\/ul>\n<pre><code>\/\/ axios\u3067\u306e\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u4f8b\r\naxios.get('...', { timeout: 5000 })\r\n  .catch(err =&gt; {\r\n    if (axios.isCancel(err)) {\r\n      console.log('Request canceled', err.message);\r\n    } else if (err.code === 'ECONNABORTED') {\r\n      console.log('Request timed out');\r\n    }\r\n  });<\/code><\/pre>\n<blockquote>\n<p><strong>\u7528\u8a9e\u89e3\u8aac\uff1aAbortController<\/strong><br \/>fetch\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9014\u4e2d\u3067\u4e2d\u65ad\uff08\u30ad\u30e3\u30f3\u30bb\u30eb\uff09\u3067\u304d\u308b\u30d6\u30e9\u30a6\u30b6\u6a19\u6e96\u306e\u4ed5\u7d44\u307f\u3002<\/p>\n<\/blockquote>\n<hr \/>\n<h3>5. \u5171\u901a\u51e6\u7406\u306e\u62bd\u8c61\u5316 \u2015 \u201c\u30a4\u30f3\u30bf\u30fc\u30bb\u30d7\u30bf\u30fc\u201d\u306e\u5f37\u307f<\/h3>\n<ul>\n<li>fetch\uff1a\u72ec\u81ea\u30e9\u30c3\u30d1\u30fc\u95a2\u6570\u304c\u5fc5\u8981\u3067\u62e1\u5f35\u30fb\u4fdd\u5b88\u304c\u7169\u96d1\u5316\u3057\u3084\u3059\u3044\u3002<\/li>\n<li>axios\uff1a<strong>\u30a4\u30f3\u30bf\u30fc\u30bb\u30d7\u30bf\u30fc<\/strong>\u3067\u30ea\u30af\u30a8\u30b9\u30c8\u30fb\u30ec\u30b9\u30dd\u30f3\u30b9\u306b<strong>\u5171\u901a\u51e6\u7406<\/strong>\u3092\u4e00\u62ec\u633f\u5165\u3002<\/li>\n<\/ul>\n<pre><code>\/\/ \u30ea\u30af\u30a8\u30b9\u30c8\u30a4\u30f3\u30bf\u30fc\u30bb\u30d7\u30bf\u30fc\u4f8b\r\naxios.interceptors.request.use(config =&gt; {\r\n  const token = localStorage.getItem('token');\r\n  if (token) config.headers.Authorization = `Bearer ${token}`;\r\n  return config;\r\n});\r\n\/\/ \u30ec\u30b9\u30dd\u30f3\u30b9\u30a4\u30f3\u30bf\u30fc\u30bb\u30d7\u30bf\u30fc\u4f8b\r\naxios.interceptors.response.use(\r\n  res =&gt; res,\r\n  err =&gt; {\r\n    if (err.response &amp;&amp; err.response.status === 401) {\r\n      window.location.href = '\/login';\r\n    }\r\n    return Promise.reject(err);\r\n  }\r\n);<\/code><\/pre>\n<hr \/>\n<h2>SWR\u30fbReact Query\u6642\u4ee3\u3067\u3082axios\u306e\u4fa1\u5024\u306f\u3042\u308b\uff1f<\/h2>\n<p>\n    \u300c<strong>SWR\u3084React Query\u304c\u4e3b\u6d41\u3067\u3001\u3082\u3046axios\u306f\u53e4\u3044\uff1f<\/strong>\u300d<br \/>\n    \u7d50\u8ad6\u306fNO\u3002<br \/>\n    <strong>SWR\/React Query<\/strong>\u306f\u300cUI\u72b6\u614b\u540c\u671f\u3068\u30ad\u30e3\u30c3\u30b7\u30e5\u300d\u304c\u5f79\u5272\u3001<strong>axios\/fetch<\/strong>\u306f\u300cHTTP\u30ea\u30af\u30a8\u30b9\u30c8\u9001\u4fe1\u300d\u306e\u5f79\u5272\u3067\u3059\u3002<br \/>\n    \u5b9f\u969b\u3001<strong>SWR\/React Query\u306efetcher<\/strong>\u3068\u3057\u3066axios\u304c\u591a\u7528\u3055\u308c\u3066\u3044\u307e\u3059\u3002\n  <\/p>\n<blockquote>\n<p><strong>\u7528\u8a9e\u89e3\u8aac\uff1aSWR<\/strong><br \/>Next.js\u958b\u767a\u5143\u304c\u63d0\u4f9b\u3059\u308bReact\u7528\u30c7\u30fc\u30bf\u53d6\u5f97\u30e9\u30a4\u30d6\u30e9\u30ea\u3002\u30ad\u30e3\u30c3\u30b7\u30e5\u3084\u81ea\u52d5\u518d\u53d6\u5f97\u304c\u7279\u5fb4\u3002<\/p>\n<p><strong>\u7528\u8a9e\u89e3\u8aac\uff1aReact Query<\/strong><br \/>React\u30a2\u30d7\u30ea\u306e\u30b5\u30fc\u30d0\u30fc\u72b6\u614b\u7ba1\u7406\u30fb\u30c7\u30fc\u30bf\u53d6\u5f97\u3092\u52b9\u7387\u5316\u3059\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3002<\/p>\n<p><strong>\u7528\u8a9e\u89e3\u8aac\uff1afetcher<\/strong><br \/>SWR\u3084React Query\u3067\u30c7\u30fc\u30bf\u53d6\u5f97\u6642\u306b\u4f7f\u3046\u300c\u5b9f\u969b\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u51e6\u7406\u300d\u3092\u62c5\u3046\u95a2\u6570\u3002<\/p>\n<\/blockquote>\n<pre><code>import useSWR from 'swr';\r\nimport axios from 'axios';\r\n\r\nconst fetcher = (url: string) =&gt; axios.get(url).then(res =&gt; res.data);\r\n\r\nfunction App() {\r\n  const { data, error } = useSWR('\/api\/user', fetcher);\r\n}<\/code><\/pre>\n<p><strong>\u5f79\u5272\u306e\u9055\u3044<\/strong>\u3092\u7406\u89e3\u3057\u3066\u4f7f\u3044\u5206\u3051\u307e\u3057\u3087\u3046\u3002<\/p>\n<hr \/>\n<h2>\u307e\u3068\u3081\uff1a\u660e\u65e5\u304b\u3089\u201c\u4fdd\u5b88\u6027UP\u201d\u306eAPI\u9023\u643a\u3092<\/h2>\n<ul>\n<li><strong>fetch\uff1a<\/strong>\u8efd\u91cf\uff06\u8ffd\u52a0\u4f9d\u5b58\u30bc\u30ed\u3002\u5358\u7d14\u306aGET\u3084\u5c0f\u898f\u6a21PJ\u306b\u6700\u9069\u3002<\/li>\n<li><strong>axios\uff1a<\/strong>\u76f4\u611f\u7684\u306a\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3001\u578b\u5b89\u5168\u3001\u5171\u901a\u51e6\u7406\u306e\u4e00\u5143\u5316\u304c\u5f37\u307f\u3002\u4e2d\u301c\u5927\u898f\u6a21PJ\u30fb\u30c1\u30fc\u30e0\u958b\u767a\u3067\u751f\u7523\u6027UP\u3002<\/li>\n<\/ul>\n<p>\n    \u300c<strong>fetch\u3067\u306e\u30a8\u30e9\u30fc\u51e6\u7406\u304c\u9762\u5012\u2026<\/strong>\u300d\u300c<strong>\u578b\u4ed8\u3051\u3067\u60a9\u3080\u2026<\/strong>\u300d<br \/>\n    \u2015\u2015\u305d\u3093\u306a\u8ab2\u984c\u304c\u3042\u308c\u3070\u3001\u305c\u3072<strong>axios\u5c0e\u5165<\/strong>\u3092\u691c\u8a0e\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u305c\u3072\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30da\u3057\u3066\u3001\u307e\u305a\u306f\u52d5\u304b\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002\n  <\/p>\n<hr \/>\n<h2>FAQ\uff5c\u3088\u304f\u3042\u308b\u7591\u554f\u306b\u56de\u7b54<\/h2>\n<ul>\n<li>\n      <strong>Q1. \u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u5dee\u306f\u3042\u308b\uff1f<\/strong><br \/>\n      \u2192 \u4f53\u611f\u3067\u304d\u308b\u307b\u3069\u306e\u5dee\u306f\u3042\u308a\u307e\u305b\u3093\u3002axios\u306e\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9\u306f\u3054\u304f\u50c5\u304b\u3067\u3059\u3002\n    <\/li>\n<li>\n      <strong>Q2. fetch\u2192axios\u79fb\u884c\u306e\u6ce8\u610f\u70b9\u306f\uff1f<\/strong><br \/>\n      \u2192 \u30ec\u30b9\u30dd\u30f3\u30b9\u53d6\u5f97\u304c<strong>res.json()<\/strong>\u2192<strong>res.data<\/strong>\u306b\u5909\u308f\u308b\u3002\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3082<strong>catch<\/strong>\u306b\u7d71\u4e00\u3055\u308c\u308b\u305f\u3081\u3001\u30b3\u30fc\u30c9\u4fee\u6b63\u304c\u5fc5\u8981\u3002\n    <\/li>\n<li>\n      <strong>Q3. axios\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\uff1f<\/strong><br \/>\n      \u30fbnpm: <strong>npm install axios<\/strong><br \/>\n      \u30fbyarn: <strong>yarn add axios<\/strong><br \/>\n      <strong>import axios from &#8216;axios&#8217;;<\/strong>\u3067\u5229\u7528\u958b\u59cb\u3002\n    <\/li>\n<\/ul>\n<p>\n    \uff08Promise\u3084\u975e\u540c\u671f\u51e6\u7406\u306e\u57fa\u790e\u306b\u3064\u3044\u3066\u306f\u300e<a href=\"https:\/\/route-zero.com\/recruit\/route\/1798\" target=\"_blank\" rel=\"noopener\">TypeScript Promise\u578b\u5b9a\u7fa9\u5b8c\u5168\u89e3\u8aac\uff5cany\u64b2\u6ec5\u3068\u4f7f\u3044\u5206\u3051<\/a\n    >\u300f\u3092\u3054\u53c2\u7167\u304f\u3060\u3055\u3044\uff09\n  <\/p>\n<hr \/>\n<\/div>\n","protected":false},"featured_media":1862,"template":"","_links":{"self":[{"href":"https:\/\/route-zero.com\/recruit\/wp-json\/wp\/v2\/route\/1861"}],"collection":[{"href":"https:\/\/route-zero.com\/recruit\/wp-json\/wp\/v2\/route"}],"about":[{"href":"https:\/\/route-zero.com\/recruit\/wp-json\/wp\/v2\/types\/route"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/route-zero.com\/recruit\/wp-json\/wp\/v2\/media\/1862"}],"wp:attachment":[{"href":"https:\/\/route-zero.com\/recruit\/wp-json\/wp\/v2\/media?parent=1861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}