Quantcast
Viewing all articles
Browse latest Browse all 8861

axiosの概要

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);// コンフィグ});

Viewing all articles
Browse latest Browse all 8861

Trending Articles