axios.js 1.0 KB

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