Skip to content

Commit

Permalink
feat: request support string as parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
suhaotian committed Feb 20, 2024
1 parent 51b2a89 commit 7515e45
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/tests/axios-compatible.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@ describe('axios compatible tests', () => {
assert.equal(Object.keys(data).sort().join(','), Object.keys(xiorData).sort().join(','));
});

it('should work same with request object', async () => {
const axiosInstance = axios.create({
baseURL,
});
const xiorInstance = xior.create({
baseURL,
});
const { data } = await axiosInstance('/get');
const { data: xiorData } = await xiorInstance.request('/get');
assert.strictEqual(JSON.stringify(data), JSON.stringify(xiorData));
});

it('should work same with request error', async () => {
const axiosInstance = axios.create({
baseURL,
Expand Down
7 changes: 5 additions & 2 deletions src/xior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ export class xior {
},
};
}
async request<T>(options?: XiorRequestConfig) {
let requestObj: XiorRequestConfig = merge(this.config || {}, options || {});
async request<T>(options?: XiorRequestConfig | string) {
let requestObj: XiorRequestConfig = merge(
this.config || {},
typeof options === 'string' ? { url: options } : options || {}
);

for (const item of this.requestInterceptors) {
requestObj = await item(requestObj);
Expand Down

0 comments on commit 7515e45

Please sign in to comment.