概述
小型的渐进式客户端HTTP请求库,以及具有相同API的Node.js模块,支持许多高级HTTP客户端特性
Small progressive client-side HTTP request library, and Node.js module with the same API, supporting many high-level HTTP client features
周下载(Weekly Downloads)
3,350,473
安装:npm install superagent -S
使用:
const superagent = require('superagent');
// callback
superagent
.post('/api/pet')
.send({ name: 'Manny', species: 'cat' }) // sends a JSON post body
.set('X-API-Key', 'foobar')
.set('accept', 'json')
.end((err, res) => {
// Calling the end function will send the request
});
// promise with then/catch
superagent.post('/api/pet').then(console.log).catch(console.error);
// promise with async/await
(async () => {
try {
const res = await superagent.post('/api/pet');
console.log(res);
} catch (err) {
console.error(err);
}
})();
网友评论