axios.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict';
  2. var utils = require('./utils');
  3. var bind = require('./helpers/bind');
  4. var Axios = require('./core/Axios');
  5. var defaults = require('./defaults');
  6. /**
  7. * Create an instance of Axios
  8. *
  9. * @param {Object} defaultConfig The default config for the instance
  10. * @return {Axios} A new instance of Axios
  11. */
  12. function createInstance(defaultConfig) {
  13. var context = new Axios(defaultConfig);
  14. var instance = bind(Axios.prototype.request, context);
  15. // Copy axios.prototype to instance
  16. utils.extend(instance, Axios.prototype, context);
  17. // Copy context to instance
  18. utils.extend(instance, context);
  19. return instance;
  20. }
  21. // Create the default instance to be exported
  22. var axios = createInstance(defaults);
  23. // Expose Axios class to allow class inheritance
  24. axios.Axios = Axios;
  25. // Factory for creating new instances
  26. axios.create = function create(instanceConfig) {
  27. return createInstance(utils.merge(defaults, instanceConfig));
  28. };
  29. // Expose Cancel & CancelToken
  30. axios.Cancel = require('./cancel/Cancel');
  31. axios.CancelToken = require('./cancel/CancelToken');
  32. axios.isCancel = require('./cancel/isCancel');
  33. // Expose all/spread
  34. axios.all = function all(promises) {
  35. return Promise.all(promises);
  36. };
  37. axios.spread = require('./helpers/spread');
  38. module.exports = axios;
  39. // Allow use of default import syntax in TypeScript
  40. module.exports.default = axios;