0
2

More than 3 years have passed since last update.

axiosの概要

Last updated at Posted at 2021-03-13

axios

axiosとは
ブラウザやnode.js上で動くPromiseベースのHTTPクライアント。非同期にHTTP通信を行いたい時容易に実装することができる。

GET通信
axios.getメソッドを使用する。
第一引数にURLを指定、then()で通信に成功した際の処理をかく。catch()でエラー時の処理を書く。
response.dataにデータが返る。

POST通信
axios.postメソッドを使用する。
POSTデータはaxios.postの第2引数で渡す。

レスポンスの構造

node.js
// レスポンス構造.
axios.get('http://localhost:3000/users').then(function(response) {
    console.log(response.data);        // レスポンスデータ
    console.log(response.status);      // ステータスコード
    console.log(response.statusText);  // ステータステキスト
    console.log(response.headers);     // レスポンスヘッダ
    console.log(response.config);      // コンフィグ
  });
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2