http-client
Advanced tools
Comparing version 2.4.2 to 3.0.0
## [HEAD] | ||
- Fix bundling with Browserify | ||
- Require consumers to provide their own global `fetch` function | ||
[HEAD]: https://github.com/mjackson/http-client/compare/latest...HEAD | ||
## [2.4.2] | ||
- Fix bundling with Browserify | ||
[2.4.2]: https://github.com/mjackson/http-client/compare/v2.4.0...v2.4.2 | ||
## [2.4.0] | ||
@@ -8,0 +14,0 @@ > Mar 18, 2016 |
@@ -8,8 +8,4 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _queryString = require('query-string'); | ||
var globalFetch = typeof fetch !== 'function' ? (typeof window === 'undefined' ? 'undefined' : _typeof(window)) !== 'object' && require('node-fetch') : fetch; | ||
var resolvePromise = function resolvePromise(promise, callback) { | ||
@@ -39,3 +35,3 @@ return promise.then(function (value) { | ||
var enhancedFetch = enhanceFetch(globalFetch); | ||
var enhancedFetch = enhanceFetch(fetch); | ||
@@ -85,3 +81,3 @@ var stringifyJSON = function stringifyJSON(json) { | ||
return enhanceFetch(function (input, options) { | ||
return stack(globalFetch, input, options); | ||
return stack(fetch, input, options); | ||
}); | ||
@@ -88,0 +84,0 @@ }; |
{ | ||
"name": "http-client", | ||
"version": "2.4.2", | ||
"version": "3.0.0", | ||
"description": "Compose HTTP clients using JavaScript's fetch API", | ||
@@ -23,3 +23,2 @@ "author": "Michael Jackson", | ||
"dependencies": { | ||
"node-fetch": "^1.3.3", | ||
"query-string": "^3.0.0" | ||
@@ -39,2 +38,3 @@ }, | ||
"gzip-size": "^3.0.0", | ||
"isomorphic-fetch": "^2.2.1", | ||
"karma": "^0.13.21", | ||
@@ -51,4 +51,3 @@ "karma-browserstack-launcher": "^0.1.10", | ||
"rimraf": "^2.5.2", | ||
"webpack": "^1.12.14", | ||
"whatwg-fetch": "^0.11.0" | ||
"webpack": "^1.12.14" | ||
}, | ||
@@ -63,6 +62,3 @@ "repository": { | ||
] | ||
}, | ||
"browser": { | ||
"node-fetch": false | ||
} | ||
} |
@@ -21,2 +21,4 @@ # http-client [![Travis][build-badge]][build] [![npm package][npm-badge]][npm] | ||
http-client requires you to bring your own [global `fetch`](https://developer.mozilla.org/en-US/docs/Web/API/GlobalFetch/fetch) function. [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch) is a great polyfill. | ||
Then, use as you would anything else: | ||
@@ -33,16 +35,2 @@ | ||
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. | ||
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 | ||
module.exports = { | ||
resolve: { | ||
packageAlias: 'browser' | ||
} | ||
} | ||
``` | ||
The UMD build is also available on [npmcdn](https://npmcdn.com): | ||
@@ -74,3 +62,3 @@ | ||
http-client also exports a "global" `fetch` function if you need it (i.e. don't want middleware). | ||
http-client also exports a base `fetch` function if you need it (i.e. don't want middleware). | ||
@@ -83,3 +71,3 @@ ## Using Callbacks | ||
All `fetch` functions in http-client support a trailing `callback` argument that you can use to handle responses and/or errors just like you're used to doing in node.js. | ||
All `fetch` functions in http-client are enhanced with a trailing `callback` argument that you can use to handle responses and/or errors just like you're used to doing in node.js. | ||
@@ -86,0 +74,0 @@ ```js |
@@ -64,8 +64,4 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _queryString = __webpack_require__(1); | ||
var globalFetch = typeof fetch !== 'function' ? ( false ? 'undefined' : _typeof(window)) !== 'object' && __webpack_require__(3) : fetch; | ||
var resolvePromise = function resolvePromise(promise, callback) { | ||
@@ -95,3 +91,3 @@ return promise.then(function (value) { | ||
var enhancedFetch = enhanceFetch(globalFetch); | ||
var enhancedFetch = enhanceFetch(fetch); | ||
@@ -141,3 +137,3 @@ var stringifyJSON = function stringifyJSON(json) { | ||
return enhanceFetch(function (input, options) { | ||
return stack(globalFetch, input, options); | ||
return stack(fetch, input, options); | ||
}); | ||
@@ -390,8 +386,2 @@ }; | ||
/***/ }, | ||
/* 3 */ | ||
/***/ function(module, exports) { | ||
/* (ignored) */ | ||
/***/ } | ||
@@ -398,0 +388,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(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){}])}); | ||
!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=e(1),o=function(n,t){return n.then(function(n){return t(null,n)},t)},u=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 u=n(t,e);return"function"==typeof r?o(u,r):u}},i=u(fetch),c=function(n){return"string"==typeof n?n:JSON.stringify(n)},f=function(n){return"string"==typeof n?n:(0,r.stringify)(n)},a=function(n,t,e){return n(t,e)};t.fetch=i;var s=t.createStack=function(){for(var n=arguments.length,t=Array(n),e=0;n>e;e++)t[e]=arguments[e];return 0===t.length?a:t.reduceRight(function(n,t){return function(e,r,o){return t(function(t,r){return n(e,t,r)},r,o)}})},p=(t.createFetch=function(){if(0===arguments.length)return i;var n=s.apply(void 0,arguments);return u(function(t,e){return n(fetch,t,e)})},function(n,t,e){(n.headers||(n.headers={}))[t]=e}),d=(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 p(o,n,t),e(r,o)}}),h=(t.auth=function(n){return d("Authorization",n)},t.accept=function(n){return d("Accept",n)},t.base=function(n){return function(t,e,r){return t(n+(e||""),r)}},t.query=function(n){var t=f(n);return function(n,e,r){return n(e+(-1===e.indexOf("?")?"?":"&")+t,r)}}),l=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&&p(o,"Content-Length",n.length),t&&p(o,"Content-Type",t),e(r,o)}},v=(t.json=function(n){return l(c(n),"application/json")},t.params=function(n){var t=f(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?h(t):l(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 v(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 v(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()})}}])}); |
1
32480
508
277
- Removednode-fetch@^1.3.3
- Removedencoding@0.1.13(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedis-stream@1.1.0(transitive)
- Removednode-fetch@1.7.3(transitive)
- Removedsafer-buffer@2.1.2(transitive)