Skip to content

Commit

Permalink
Merge pull request #21 from kirill-782/master
Browse files Browse the repository at this point in the history
Non get params moved to body from query
  • Loading branch information
Capster committed Mar 2, 2024
2 parents 74fefbc + dc25049 commit 22c269a
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 shouldUseBodyParams = type !== 'GET';

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

if (!shouldUseBodyParams) {
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 (shouldUseBodyParams && params) {
headers.set('Content-Type', 'application/json');
}

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

Expand Down

0 comments on commit 22c269a

Please sign in to comment.