set chaining's default to true

This commit is contained in:
Wessel Tip
2019-04-12 18:34:09 +02:00
parent c581ae33b0
commit a72c2fd649
3 changed files with 8 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
<img src="https://wessel.meek.moe/wumpfetch/logo.svg" align="left" style="border-radius: 5%;" width="192px" height="192px"/> <img src="https://wessel.meek.moe/wumpfetch/logo.svg" align="left" width="180px" height="180px"/>
<img align="left" width="0" height="192px" hspace="10"/> <img align="left" width="0" height="192px" hspace="10"/>
> <a href="https://github.com/PassTheWessel/wumpfetch">Wumpfetch</a> - A fast and easy to use HTTP client > <a href="https://github.com/PassTheWessel/wumpfetch">Wumpfetch</a> - A fast and easy to use HTTP client
@@ -46,15 +46,17 @@ const w = require('wumpfetch');
// Using an URL and custom options // Using an URL and custom options
;(async() => { ;(async() => {
let req = await w('https://aws.random.cat/meow', { let req = await w('https://aws.random.cat/meow', {
chaining: false,
headers: { headers: {
'User-Agent': 'Project/0.0.1' 'User-Agent': 'Project/0.0.1'
} }
}); });
// Only URL // Only URL
req = await w('https://aws.random.cat/meow'); req = await w('https://aws.random.cat/meow', { chaining: false });
// Only options // Only options
req = await w({ req = await w({
url: 'https://aws.random.cat/meow', url: 'https://aws.random.cat/meow',
chaining: false,
headers: { headers: {
'User-Agent': 'Project/0.0.1' 'User-Agent': 'Project/0.0.1'
} }
@@ -76,7 +78,7 @@ You can also chain methods by adding `chaining: true` to `options`
const w = require('wumpfetch'); const w = require('wumpfetch');
;(async() => { ;(async() => {
const r = await w('https://my-site.com/postboi', { method: 'POST', chaining: true }) const r = await w('https://my-site.com/postboi', { method: 'POST' })
.timeout(1000) // Set a 1s timeout .timeout(1000) // Set a 1s timeout
.query('video', 'wumpboye') // Add a query .query('video', 'wumpboye') // Add a query
.header({ 'Authorization': 'Pablito' }) // Set a header .header({ 'Authorization': 'Pablito' }) // Set a header

View File

@@ -5,8 +5,8 @@ console.log(`Using wumpfetch v${wump.version} [${wump.userAgent}]\n\n`);
;(async() => { ;(async() => {
const requests = [ const requests = [
await wump({ url: 'https://jsonplaceholder.typicode.com/todos/1', parse: 'json', chaining: true }).send(), await wump({ url: 'https://jsonplaceholder.typicode.com/todos/1', parse: 'json' }).send(),
await wump('https://jsonplaceholder.typicode.com/todos/1') await wump('https://jsonplaceholder.typicode.com/todos/1', { chaining: false })
]; ];
console.log(`Test 1: \n${util.inspect(requests[0].body)}\n\n`); console.log(`Test 1: \n${util.inspect(requests[0].body)}\n\n`);

View File

@@ -24,7 +24,7 @@ module.exports = class WumpRequest {
'SDA': obj && typeof o.sendDataAs === 'string' ? o.sendDataAs : obj && o.data && typeof o.data === 'object' ? 'json' : undefined, 'SDA': obj && typeof o.sendDataAs === 'string' ? o.sendDataAs : obj && o.data && typeof o.data === 'object' ? 'json' : undefined,
'data': obj && o.body ? o.body : obj && o.data ? o.data : obj && o.json ? o.json : obj && o.form ? qs.stringify(o.form) : undefined, 'data': obj && o.body ? o.body : obj && o.data ? o.data : obj && o.json ? o.json : obj && o.form ? qs.stringify(o.form) : undefined,
'parse': obj && o.parse ? o.parse : undefined, 'parse': obj && o.parse ? o.parse : undefined,
'chain': !!(obj && o.chaining), 'chain': obj && typeof o.chaining === 'boolean' ? o.chaining : true,
'follow': !!(obj && o.followRedirects), 'follow': !!(obj && o.followRedirects),
'rHeaders': obj && typeof o.headers === 'object' ? o.headers : {}, 'rHeaders': obj && typeof o.headers === 'object' ? o.headers : {},
'streamed': !!(obj && o.streamed), 'streamed': !!(obj && o.streamed),