Skip to content

A very basic API compatible replacement for node-fetch, without leaking memory when making thousands of requests

License

Notifications You must be signed in to change notification settings

ronny1982/node-fetch-lite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-fetch-lite

A very basic API compatible replacement for node-fetch, without leaking memory when making thousands of requests

Sample Usage

Perform GET

import fetch, { Request } from 'node-fetch-lite';

(async function get() {
    const request = new Request('http://httpbin.org/json');
    const response = await fetch(request);
    const data = await response.json();
    console.log('GET / STATUS:', response.status);
    console.log('GET / CONTENT:', response.headers.get('content-type'));
    console.log('GET / DATA:', data);
})();

Perform POST

import fetch, { Request } from 'node-fetch-lite';

(async function post() {
    const request = new Request('https://httpbin.org/post', {
        method: 'POST',
        body: JSON.stringify({
            name: 'John Smith',
            age: 123
        }),
        headers: {
            'User-Agent': 'node-fetch-lite',
            'Content-Type': 'application/json'
        }
    });
    const response = await fetch(request);
    const data = await response.json();
    console.log('POST / STATUS:', response.status);
    console.log('POST / CONTENT:', response.headers.get('content-type'));
    console.log('POST / DATA:', data);
})();

About

A very basic API compatible replacement for node-fetch, without leaking memory when making thousands of requests

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published