mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Supporting a fetch like API
This commit is contained in:
+4
-4
@@ -6,11 +6,11 @@ var dispatchRequest = require('./core/dispatchRequest');
|
|||||||
var InterceptorManager = require('./core/InterceptorManager');
|
var InterceptorManager = require('./core/InterceptorManager');
|
||||||
|
|
||||||
var axios = module.exports = function (config) {
|
var axios = module.exports = function (config) {
|
||||||
// Allow for axios('example/url')
|
// Allow for axios('example/url'[, config]) a la fetch API
|
||||||
if (typeof config === 'string') {
|
if (typeof config === 'string') {
|
||||||
config = {
|
config = utils.merge({
|
||||||
url: config
|
url: arguments[0]
|
||||||
};
|
}, arguments[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
config = utils.merge({
|
config = utils.merge({
|
||||||
|
|||||||
@@ -18,6 +18,23 @@ describe('requests', function () {
|
|||||||
request = jasmine.Ajax.requests.mostRecent();
|
request = jasmine.Ajax.requests.mostRecent();
|
||||||
|
|
||||||
expect(request.url).toBe('/foo');
|
expect(request.url).toBe('/foo');
|
||||||
|
expect(request.method).toBe('GET');
|
||||||
|
done();
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow string arg as url, and config arg', function (done) {
|
||||||
|
var request;
|
||||||
|
|
||||||
|
axios('/foo', {
|
||||||
|
method: 'POST'
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
request = jasmine.Ajax.requests.mostRecent();
|
||||||
|
|
||||||
|
expect(request.url).toBe('/foo');
|
||||||
|
expect(request.method).toBe('POST');
|
||||||
done();
|
done();
|
||||||
}, 0);
|
}, 0);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user