axios
httpクライアントライブラリ
2022/10/4にv1.0.0が出た ref
github
docs
#WIP
https://zenn.dev/team_zenn/articles/migrated-from-axios-to-fetch-api
脱axiosしてサイズ削減
わざわざaxiosを入れるべきなのか悩む
node.jsでもfetch()に対応した
next.js v13は何かfetch()をカスタムしているので使ったほうが良い
残っているのはPOST系の処理だが、ただそれだけのためにわざわざaxiosを入れるのか?という気持ちになるmrsekut.icon
別にfetchでもPOSTできる
#??
postメソッドの第3引数のconfigってなに?
axiosのerror handling
400や500が返ってきたときは自動的にthrowする?
20x以外はエラーになるらしい
https://axios-http.com/docs/handling_errors
https://dev.classmethod.jp/articles/typescript-typing-exception-objects-in-axios-trycatch/
type guradする関数Axios.isAxiosError()が提供されている
https://qiita.com/yuta-katayama-23/items/5b8bf72236eec9cadf41
https://zenn.dev/sa2knight/articles/axios-major-version
v1.0.0で変わったこと
https://www.youtube.com/watch?t=2461&v=Rp6yNsHgxhY&feature=youtu.be
POSTでheaderとbodyを指定する
code:ts
const headers = {
'Content-Type': 'application/json',
};
const res = await axios.post(url, params, { headers });
Mockを作るのがかんたん
/mrsekut-book-483996937X/251
https://azukiazusa.dev/blog/axios/