superagent-fetch
v1.1.0
Published
Use it to display your superagent request likes fetch method. Useful when want to compare with a request copied from browser.
Downloads
2
Readme
superagent-fetch
Use it to display your superagent request likes fetch method. Useful when want to compare with a request copied from browser.
const agent = require('superagent');
const superagentToFetch = require('superagent-fetch');
const fetched = agent
.get('/status')
.use(superagentToFetch)
.toFetch();
console.log(fetched);
// Will display this
/*
fetch("/status", {
"method": "GET"
});
*/
A more commplex example:
const agent = require('superagent');
const superagentToFetch = require('superagent-fetch');
const fetched = agent
.post('/status')
.set('Content-Type', 'application/json; charset=utf-8')
.send({foo: 'bar', exec: true})
.use(superagentToFetch)
.toFetch();
console.log(fetched);
// Will display this
/*
fetch("/status", {
"headers": {
"content-type": "application/json; charset=utf-8"
},
"body": "{\"foo\":\"bar\",\"exec\":true}",
"method": "POST"
});
*/