mirror of
https://github.com/tenrok/axios.git
synced 2026-06-11 18:02:32 +03:00
6b9b05b907
* Fixed isFormData predicate;
Added support for automatic object serialization to FormData if `Content-Type` is `multipart/form-data`;
Added support for FormData to be overloaded using `config.env.FormData` option;
Added support for FormData in node.js environment through `form-data` package;
* Added the `form-data` package as a dependency for the server build;
Added tests for FormData payload;
* Added FormData automatic serialization section;
Refactored cancellation section;
* Reworked toFormData helper;
Expose toFormData helper as a static method;
Refactored transform request;
Added kindOf, kindOfTest, endsWith, isTypedArray util;
Refactored utils.js to use kindOf for tests;
* Fixed isFormData predicate; (#4413)
Added support for automatic object serialization to FormData if `Content-Type` is `multipart/form-data`;
Added support for FormData to be overloaded using `config.env.FormData` option;
Added support for FormData in node.js environment using `form-data` package;
(cherry picked from commit 73e3bdb883)
* Added shortcut methods `postForm`, `putForm`, `patchForm` to submit a Form;
Added ability to submit FileList object as a FormData;
Updated README.md;
* Updated README.md;
59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
var utils = require('./utils');
|
|
var bind = require('./helpers/bind');
|
|
var Axios = require('./core/Axios');
|
|
var mergeConfig = require('./core/mergeConfig');
|
|
var defaults = require('./defaults');
|
|
|
|
/**
|
|
* Create an instance of Axios
|
|
*
|
|
* @param {Object} defaultConfig The default config for the instance
|
|
* @return {Axios} A new instance of Axios
|
|
*/
|
|
function createInstance(defaultConfig) {
|
|
var context = new Axios(defaultConfig);
|
|
var instance = bind(Axios.prototype.request, context);
|
|
|
|
// Copy axios.prototype to instance
|
|
utils.extend(instance, Axios.prototype, context);
|
|
|
|
// Copy context to instance
|
|
utils.extend(instance, context);
|
|
|
|
// Factory for creating new instances
|
|
instance.create = function create(instanceConfig) {
|
|
return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
|
};
|
|
|
|
return instance;
|
|
}
|
|
|
|
// Create the default instance to be exported
|
|
var axios = createInstance(defaults);
|
|
|
|
// Expose Axios class to allow class inheritance
|
|
axios.Axios = Axios;
|
|
|
|
// Expose Cancel & CancelToken
|
|
axios.Cancel = require('./cancel/Cancel');
|
|
axios.CancelToken = require('./cancel/CancelToken');
|
|
axios.isCancel = require('./cancel/isCancel');
|
|
axios.VERSION = require('./env/data').version;
|
|
axios.toFormData = require('./helpers/toFormData');
|
|
|
|
// Expose all/spread
|
|
axios.all = function all(promises) {
|
|
return Promise.all(promises);
|
|
};
|
|
axios.spread = require('./helpers/spread');
|
|
|
|
// Expose isAxiosError
|
|
axios.isAxiosError = require('./helpers/isAxiosError');
|
|
|
|
module.exports = axios;
|
|
|
|
// Allow use of default import syntax in TypeScript
|
|
module.exports.default = axios;
|