superagent-fetch

1.1.0 • Public • Published

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"
});
*/

Readme

Keywords

none

Package Sidebar

Install

npm i superagent-fetch

Weekly Downloads

3

Version

1.1.0

License

MIT

Unpacked Size

4.17 kB

Total Files

6

Last publish

Collaborators

  • mathrobin