Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non get params moved to body from query #21

Merged
merged 2 commits into from
Mar 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading