mirror of
https://github.com/Wessel/wumpfetch.git
synced 2026-06-06 07:35:42 +02:00
75bf5323e8aaf00a97e3ac6a083ac1bd203bb848
Changes: * Fixed gulpfile.js formatting * Fixed package.json and made it lighter * Made index.js and WumpRequest.js lighter * Made example lighter * Fixed grammar issue in WumpRequest.js * Fixed spacing issue in test * Improved README.md and made it lighter
Wumpfetch
A lightweight and fast Node.js HTTP client which can be used in various ways
Installing
$ yarn add wumpfetch # Install w/ Yarn (the superior package manager)
$ npm i wumpfetch # Install w/ NPM
Usage
Code
const w = require('wumpfetch');
;(async() => {
const r = await w('https://aws.random.cat/meow').send();
console.log(r.json());
});
Result
$ node test.js
{ file: 'https://purr.objects-us-east-1.dream.io/i/100_-_rURSo7L.gif' }
Sending data in a JSON body to a server
Chaining methods
const w = require('wumpfetch');
;(async() => {
const r = await w('https://my-site.com/postboi', 'POST')
.timeout(1000) // Set a 1s timeout
.query('video', 'wumpboye') // Add a query
.header({ 'Authorization': 'Pablito' }) // Set a header
.body({ x: 'y', z: 1, beep: 'boop', chocolate: true }) // Send a json body
.send(); // Finish the chain by sending the rquest
console.log(r.json()); // Returns the response in a JSON format
})();
Object
const w = require('wumpfetch');
;(async() => {
const r = await w({
url: 'https://my-site.com/postboi',
data: { 'bear': 'cop' },
method: 'POST',
headers: {
'Authorization': 'Pablo'
}
});
console.log(r.json());
})();
or
const w = require('wumpfetch');
;(async() => {
const r = await w('https://my-site.com/postboi', { method: 'GET' });
console.log(r.json());
})();z
Why use Wumpfetch?
Wumpfetch is a lightweight and fast request library comparing to other packages such as request which is 4.46mb!
(6.2kb concatenated and 4.4kb minified, both in /dest)
Languages
JavaScript
96.9%
TypeScript
3.1%