0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

TypeScript の http クライアントの使い方 (Get)

Last updated at Posted at 2020-05-02

ライブラリーのインストール

sudo npm install -g axios

プログラム

http_get.ts
// ---------------------------------------------------------------
//	http_get.ts
//
//					Feb/28/2022
//
// ---------------------------------------------------------------
console.log ("*** 開始 ***")
 
const axios = require('axios')

const url = "https://httpbin.org/get"
axios.get(url)
	.then(function (response: any) {
	console.log(response.data);
	})
	.catch(function (error: any) {
		console.log("*** error ***")
		console.log(error)
		})
	.then(function () {
		console.log ("*** 終了 ***")
		})

// ---------------------------------------------------------------
 

実行結果

$ bun run http_get.ts 
*** 開始 ***
{
  args: {},
  headers: {
    Accept: "application/json, text/plain, */*",
    "Accept-Encoding": "gzip, compress, deflate, br",
    Host: "httpbin.org",
    "User-Agent": "axios/1.7.2",
    "X-Amzn-Trace-Id": "Root=1-667a7dd6-495b2de22c0dde0e150ff73f",
  },
  origin: "219.126.138.166",
  url: "https://httpbin.org/get",
}
*** 終了 ***

確認したバージョン

$ node --version
v22.3.0

$ bun --version
1.1.16
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?