Skip to content

Commit

Permalink
fix: try setting urlsearchparams as body
Browse files Browse the repository at this point in the history
  • Loading branch information
animify committed Feb 21, 2020
1 parent f7147aa commit 0bb05df
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class Request {
try {
const requestOptions: RequestInit = {
method: opts.method,
body: JSON.stringify(opts.body),
body: new URLSearchParams(opts.body),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
Expand All @@ -26,7 +26,7 @@ export default class Request {
};
}

const response = await fetch(Request.buildURL(opts.url), requestOptions);
const response = await fetch(Request.buildURL(opts.url, opts.body), requestOptions);

Request.checkStatus(response);

Expand All @@ -44,8 +44,10 @@ export default class Request {
Request._authToken = token;
}

public static buildURL(url: string) {
return `https://api.dribbble.com/v2/${url}`.replace(/([^:]\/)\/+/g, '$1');
public static buildURL(url: string, body?: FetchOptions['body']) {
const apiUrl = `https://api.dribbble.com/v2/${url}`.replace(/([^:]\/)\/+/g, '$1');

return apiUrl;
}

private static checkStatus(response: Response) {
Expand Down

0 comments on commit 0bb05df

Please sign in to comment.