http-client
Advanced tools
Comparing version 2.4.1 to 2.4.2
@@ -0,1 +1,7 @@ | ||
## [HEAD] | ||
- Fix bundling with Browserify | ||
[HEAD]: https://github.com/mjackson/http-client/compare/latest...HEAD | ||
## [2.4.0] | ||
@@ -2,0 +8,0 @@ > Mar 18, 2016 |
{ | ||
"name": "http-client", | ||
"version": "2.4.1", | ||
"version": "2.4.2", | ||
"description": "Compose HTTP clients using JavaScript's fetch API", | ||
"author": "Michael Jackson", | ||
"license": "MIT", | ||
"webpack": "lib", | ||
"browser": "umd/http-client.min.js", | ||
"main": "lib", | ||
@@ -57,3 +55,11 @@ "files": [ | ||
"url": "https://github.com/mjackson/http-client.git" | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"es2015" | ||
] | ||
}, | ||
"browser": { | ||
"node-fetch": false | ||
} | ||
} |
@@ -12,3 +12,3 @@ # http-client [![Travis][build-badge]][build] [![npm package][npm-badge]][npm] | ||
- Preserve the full capabilities of the fetch API | ||
- Provide an extendable middleware API | ||
- Provide an extendable middleware API | ||
- Use the same API on both client and server | ||
@@ -33,21 +33,16 @@ | ||
In node, http-client automatically uses the [node-fetch](https://github.com/bitinn/node-fetch) library under the hood so no extra configuration is necessary. You'll need to be running node >= 4. Be sure to read about the [known differences](https://github.com/bitinn/node-fetch/blob/master/LIMITS.md) between node-fetch and [the fetch spec](https://fetch.spec.whatwg.org/). | ||
You'll need to shim `window.fetch` in [browsers that do not support it](http://caniuse.com/#feat=fetch) (Safari and IE). [github/fetch](https://github.com/github/fetch) is a great polyfill. | ||
If you're bundling http-client with [webpack](https://webpack.github.io/), you'll want to include the following in your webpack config: | ||
http-client uses [the `browser` field](https://github.com/defunctzombie/package-browser-field-spec) in its `package.json` to avoid bundling `node-fetch` in browsers. In [Browserify](http://browserify.org/), this will just work™. If you're bundling http-client with [webpack](https://webpack.github.io/), you'll either need to ignore `node-fetch` explicitly or include the following in your config: | ||
```js | ||
const webpack = require('webpack') | ||
module.exports = { | ||
plugins: [ | ||
new webpack.IgnorePlugin(/node-fetch/), | ||
new webpack.DefinePlugin({ | ||
'typeof window': JSON.stringify('object') | ||
}) | ||
] | ||
resolve: { | ||
packageAlias: 'browser' | ||
} | ||
} | ||
``` | ||
In node, http-client automatically uses the [node-fetch](https://github.com/bitinn/node-fetch) library under the hood so no extra configuration is necessary. You'll need to be running node >= 4. Be sure to read about the [known differences](https://github.com/bitinn/node-fetch/blob/master/LIMITS.md) between node-fetch and [the fetch spec](https://fetch.spec.whatwg.org/). | ||
The UMD build is also available on [npmcdn](https://npmcdn.com): | ||
@@ -54,0 +49,0 @@ |
@@ -68,3 +68,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var globalFetch = typeof fetch !== 'function' ? ( false ? 'undefined' : _typeof(window)) !== 'object' && __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module \"node-fetch\""); e.code = 'MODULE_NOT_FOUND'; throw e; }())) : fetch; | ||
var globalFetch = typeof fetch !== 'function' ? ( false ? 'undefined' : _typeof(window)) !== 'object' && __webpack_require__(3) : fetch; | ||
@@ -339,3 +339,3 @@ var resolvePromise = function resolvePromise(promise, callback) { | ||
if (!ret[key]) { | ||
if (!ret.hasOwnProperty(key)) { | ||
ret[key] = val; | ||
@@ -349,3 +349,3 @@ } else if (Array.isArray(ret[key])) { | ||
return ret; | ||
}, Object.create(null)); | ||
}, {}); | ||
}; | ||
@@ -390,2 +390,8 @@ | ||
/***/ }, | ||
/* 3 */ | ||
/***/ function(module, exports) { | ||
/* (ignored) */ | ||
/***/ } | ||
@@ -392,0 +398,0 @@ /******/ ]) |
@@ -1,1 +0,1 @@ | ||
!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.HTTPClient=t():n.HTTPClient=t()}(this,function(){return function(n){function t(r){if(e[r])return e[r].exports;var o=e[r]={exports:{},id:r,loaded:!1};return n[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var e={};return t.m=n,t.c=e,t.p="",t(0)}([function(n,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.requestInfo=t.parseJSON=t.parseText=t.handleResponse=t.params=t.json=t.body=t.query=t.base=t.accept=t.auth=t.header=t.method=t.createFetch=t.createStack=t.fetch=void 0;var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol?"symbol":typeof n},o=e(1),u="function"!=typeof fetch?"object"!==r(window)&&e(!function(){var n=new Error('Cannot find module "node-fetch"');throw n.code="MODULE_NOT_FOUND",n}()):fetch,i=function(n,t){return n.then(function(n){return t(null,n)},t)},c=function(n){return function(t,e,r){"function"!=typeof r&&("function"==typeof e?(r=e,e=void 0):"function"==typeof t&&(r=t,t=void 0));var o=n(t,e);return"function"==typeof r?i(o,r):o}},f=c(u),a=function(n){return"string"==typeof n?n:JSON.stringify(n)},s=function(n){return"string"==typeof n?n:(0,o.stringify)(n)},p=function(n,t,e){return n(t,e)};t.fetch=f;var d=t.createStack=function(){for(var n=arguments.length,t=Array(n),e=0;n>e;e++)t[e]=arguments[e];return 0===t.length?p:t.reduceRight(function(n,t){return function(e,r,o){return t(function(t,r){return n(e,t,r)},r,o)}})},l=(t.createFetch=function(){if(0===arguments.length)return f;var n=d.apply(void 0,arguments);return c(function(t,e){return n(u,t,e)})},function(n,t,e){(n.headers||(n.headers={}))[t]=e}),h=(t.method=function(n){return function(t,e){var r=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];return r.method=n,t(e,r)}},t.header=function(n,t){return function(e,r){var o=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];return l(o,n,t),e(r,o)}}),y=(t.auth=function(n){return h("Authorization",n)},t.accept=function(n){return h("Accept",n)},t.base=function(n){return function(t,e,r){return t(n+(e||""),r)}},t.query=function(n){var t=s(n);return function(n,e,r){return n(e+(-1===e.indexOf("?")?"?":"&")+t,r)}}),v=t.body=function(n,t){return function(e,r){var o=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];return o.body=n,null!=n.length&&l(o,"Content-Length",n.length),t&&l(o,"Content-Type",t),e(r,o)}},g=(t.json=function(n){return v(a(n),"application/json")},t.params=function(n){var t=s(n);return function(n,e){var r=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],o=(r.method||"GET").toUpperCase(),u="GET"===o||"HEAD"===o?y(t):v(t,"application/x-www-form-urlencoded");return u(n,e,r)}},t.handleResponse=function(n){return function(t,e,r){return t(e,r).then(n)}});t.parseText=function(){var n=arguments.length<=0||void 0===arguments[0]?"textString":arguments[0];return g(function(t){return t.text().then(function(e){return t[n]=e,t})})},t.parseJSON=function(){var n=arguments.length<=0||void 0===arguments[0]?"jsonData":arguments[0];return g(function(t){return t.json().then(function(e){return t[n]=e,t},function(n){throw new Error("Error parsing JSON: "+n.stack)})})},t.requestInfo=function(){return function(n,t,e){return n(t,e).then(function(n){return n.requestInput=t,n.requestOptions=e,n},function(){var n=arguments.length<=0||void 0===arguments[0]?new Error:arguments[0];throw n.requestInput=t,n.requestOptions=e,n})}}},function(n,t,e){"use strict";var r=e(2);t.extract=function(n){return n.split("?")[1]||""},t.parse=function(n){return"string"!=typeof n?{}:(n=n.trim().replace(/^(\?|#|&)/,""),n?n.split("&").reduce(function(n,t){var e=t.replace(/\+/g," ").split("="),r=e.shift(),o=e.length>0?e.join("="):void 0;return r=decodeURIComponent(r),o=void 0===o?null:decodeURIComponent(o),n[r]?Array.isArray(n[r])?n[r].push(o):n[r]=[n[r],o]:n[r]=o,n},Object.create(null)):{})},t.stringify=function(n){return n?Object.keys(n).sort().map(function(t){var e=n[t];return void 0===e?"":null===e?t:Array.isArray(e)?e.slice().sort().map(function(n){return r(t)+"="+r(n)}).join("&"):r(t)+"="+r(e)}).filter(function(n){return n.length>0}).join("&"):""}},function(n,t){"use strict";n.exports=function(n){return encodeURIComponent(n).replace(/[!'()*]/g,function(n){return"%"+n.charCodeAt(0).toString(16).toUpperCase()})}}])}); | ||
!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.HTTPClient=t():n.HTTPClient=t()}(this,function(){return function(n){function t(r){if(e[r])return e[r].exports;var o=e[r]={exports:{},id:r,loaded:!1};return n[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var e={};return t.m=n,t.c=e,t.p="",t(0)}([function(n,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.requestInfo=t.parseJSON=t.parseText=t.handleResponse=t.params=t.json=t.body=t.query=t.base=t.accept=t.auth=t.header=t.method=t.createFetch=t.createStack=t.fetch=void 0;var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol?"symbol":typeof n},o=e(1),u="function"!=typeof fetch?"object"!==r(window)&&e(3):fetch,i=function(n,t){return n.then(function(n){return t(null,n)},t)},c=function(n){return function(t,e,r){"function"!=typeof r&&("function"==typeof e?(r=e,e=void 0):"function"==typeof t&&(r=t,t=void 0));var o=n(t,e);return"function"==typeof r?i(o,r):o}},f=c(u),a=function(n){return"string"==typeof n?n:JSON.stringify(n)},s=function(n){return"string"==typeof n?n:(0,o.stringify)(n)},p=function(n,t,e){return n(t,e)};t.fetch=f;var d=t.createStack=function(){for(var n=arguments.length,t=Array(n),e=0;n>e;e++)t[e]=arguments[e];return 0===t.length?p:t.reduceRight(function(n,t){return function(e,r,o){return t(function(t,r){return n(e,t,r)},r,o)}})},l=(t.createFetch=function(){if(0===arguments.length)return f;var n=d.apply(void 0,arguments);return c(function(t,e){return n(u,t,e)})},function(n,t,e){(n.headers||(n.headers={}))[t]=e}),h=(t.method=function(n){return function(t,e){var r=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];return r.method=n,t(e,r)}},t.header=function(n,t){return function(e,r){var o=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];return l(o,n,t),e(r,o)}}),y=(t.auth=function(n){return h("Authorization",n)},t.accept=function(n){return h("Accept",n)},t.base=function(n){return function(t,e,r){return t(n+(e||""),r)}},t.query=function(n){var t=s(n);return function(n,e,r){return n(e+(-1===e.indexOf("?")?"?":"&")+t,r)}}),v=t.body=function(n,t){return function(e,r){var o=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];return o.body=n,null!=n.length&&l(o,"Content-Length",n.length),t&&l(o,"Content-Type",t),e(r,o)}},g=(t.json=function(n){return v(a(n),"application/json")},t.params=function(n){var t=s(n);return function(n,e){var r=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],o=(r.method||"GET").toUpperCase(),u="GET"===o||"HEAD"===o?y(t):v(t,"application/x-www-form-urlencoded");return u(n,e,r)}},t.handleResponse=function(n){return function(t,e,r){return t(e,r).then(n)}});t.parseText=function(){var n=arguments.length<=0||void 0===arguments[0]?"textString":arguments[0];return g(function(t){return t.text().then(function(e){return t[n]=e,t})})},t.parseJSON=function(){var n=arguments.length<=0||void 0===arguments[0]?"jsonData":arguments[0];return g(function(t){return t.json().then(function(e){return t[n]=e,t},function(n){throw new Error("Error parsing JSON: "+n.stack)})})},t.requestInfo=function(){return function(n,t,e){return n(t,e).then(function(n){return n.requestInput=t,n.requestOptions=e,n},function(){var n=arguments.length<=0||void 0===arguments[0]?new Error:arguments[0];throw n.requestInput=t,n.requestOptions=e,n})}}},function(n,t,e){"use strict";var r=e(2);t.extract=function(n){return n.split("?")[1]||""},t.parse=function(n){return"string"!=typeof n?{}:(n=n.trim().replace(/^(\?|#|&)/,""),n?n.split("&").reduce(function(n,t){var e=t.replace(/\+/g," ").split("="),r=e.shift(),o=e.length>0?e.join("="):void 0;return r=decodeURIComponent(r),o=void 0===o?null:decodeURIComponent(o),n.hasOwnProperty(r)?Array.isArray(n[r])?n[r].push(o):n[r]=[n[r],o]:n[r]=o,n},{}):{})},t.stringify=function(n){return n?Object.keys(n).sort().map(function(t){var e=n[t];return void 0===e?"":null===e?t:Array.isArray(e)?e.slice().sort().map(function(n){return r(t)+"="+r(n)}).join("&"):r(t)+"="+r(e)}).filter(function(n){return n.length>0}).join("&"):""}},function(n,t){"use strict";n.exports=function(n){return encodeURIComponent(n).replace(/[!'()*]/g,function(n){return"%"+n.charCodeAt(0).toString(16).toUpperCase()})}},function(n,t){}])}); |
28
34333
6
516
289