Files
wumpfetch/README.md
David Ralph d360bdcc07 More Improvements (see full info)
Here's what I did and why I did it:
* Remove README.md information about why use Wumpfetch - Users already know it's light from the start and from package phobia, no point adding extra unneeded information.
* Made gulpfile.js lighter - Made it like the other files
* Edit LICENSE - There was an unneeded gap
* Index.js modifications -  No longer does it hard code the package name and URL, making life easier for people forking it or using it in business. Also changed request to req to make it lighter!
* .gitignore edit - Removed unneeded "/"
* WumpRequest.js Improvements - Package name and URL are also no longer hard coded here, renamed consts to decrease file size.

Now under 10kb!
2019-04-11 18:28:38 +01:00

1.6 KiB

Wumpfetch

A lightweight and fast Node.js HTTP client which can be used in various ways

Typings | GitHub | NPM

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());
})();