Try   HackMD

分享幾個實際被用到的 library

got

sindresorhus/got: 🌐 Human-friendly and powerful HTTP request library for Node.js

Node.js 的一個 Human-friendly 的強大 HTTP request library

  • ky 開發團隊出的一個 request library
  • 支援 Http/2(需要 Node.js 15.10.0 或更高版本)
  • 不支援瀏覽器上運行(如需在瀏覽器上運行,官方建議使用該團隊出的另一個 Library:ky

亮點: HTTP/2 support

根據官網的表,got 支援 HTTP/2,在 Node.js 15.10.0 以上的版本中可以使用。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

亮點: JSON mode

Got 有一個專門的選項來處理 JSON playload。
具體的說,got 有一個會回傳 Promise<T>.json<T>() 函數可以用來處理 json。

import got from 'got';

const {data} = await got.post('https://httpbin.org/anything', {
	json: {
		hello: 'world'
	}
}).json();

console.log(data);
//=> {"hello": "world"}