A very basic API compatible replacement for node-fetch, without leaking memory when making thousands of requests
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);
})();
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);
})();