Skip to content

Commit

Permalink
Non get params moved to body from query
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-782 committed Feb 27, 2024
1 parent 74fefbc commit be68bd7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/apiProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ export const apiProvider = ({
let accessToken: Token = token;

const apiRequest: RequestHandler = async (type, endpoint, params): Promise<any> => {
const searchParams = new URLSearchParams(Object.entries(params));
const fullPath = `/api${endpoint}?${searchParams.toString()}`;
const inBodyParams = type !== "GET"; // || type !== "HEAD"

let fullPath = `/api${endpoint}`;

if(!inBodyParams) {
const searchParams = new URLSearchParams(Object.entries(params));
fullPath += "?" + searchParams
}

const headers = new Headers({
'User-Agent': clientName,
Expand All @@ -71,9 +77,14 @@ export const apiProvider = ({
headers.set('Authorization', `Bearer ${accessToken}`);
}

if(inBodyParams && params) {
headers.set('Content-Type', `application/json`);
}

return request(fullPath, {
method: type,
headers: headers,
body: inBodyParams && params ? JSON.stringify(params) : undefined
});
};

Expand Down

0 comments on commit be68bd7

Please sign in to comment.