diff --git a/index.test.ts b/index.test.ts index 940747e..a1ff8e6 100644 --- a/index.test.ts +++ b/index.test.ts @@ -56,4 +56,20 @@ describe("fetchAdapter", () => { expect(res.status).toBeLessThan(300); expect(res.headers["content-type"]).toContain("application/json"); }); + + //test to check query params + test("query params", async () => { + //make the request + const res = await client.get("/users/search", { + params: { + q: "John", + }, + }); + + console.log(res.data); + + expect(res.status).toBeGreaterThanOrEqual(200); + expect(res.status).toBeLessThan(300); + expect(res.headers["content-type"]).toContain("application/json"); + }); }); diff --git a/index.ts b/index.ts index f061b57..5053add 100644 --- a/index.ts +++ b/index.ts @@ -13,7 +13,12 @@ export default function (fetch: fetch): AxiosAdapter { //return the adapter using that fetch implementation return async (config: InternalAxiosRequestConfig): AxiosPromise => { //get the url from the config - const url = (config.baseURL ? config.baseURL : "") + config.url; + let url = (config.baseURL ? config.baseURL : "") + config.url; + //append params to the url if they exist + if (config.params) { + const params = new URLSearchParams(config.params).toString(); + url += "?" + params; + } if (!url) { throw new AxiosError( "no url specified. @fetchAdapter", @@ -67,9 +72,9 @@ export default function (fetch: fetch): AxiosAdapter { //if the error is not something we can handle, throw a generic error throw new AxiosError( - "an error occurred while making the request.\n" + - (err as Error).message + - "\n@fetchAdapter", + "an error occurred while making the request.(" + + err + + ") @fetchAdapter", "777 (FETCH_ERROR)", config, request diff --git a/package.json b/package.json index 7d33264..103d01b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fetchify-axios", "description": "Fetchify Axios is a fetch adapter for Axios that takes any function that implements the standard fetchAPI interface!", - "version": "1.0.1", + "version": "1.0.2", "main": "index.js", "module": "index.js", "types": "index.ts",