Skip to content

Commit

Permalink
fix(request): set GET as default request method
Browse files Browse the repository at this point in the history
Defaults request method to "GET" to avoid setting the "Content-Type" to json for requests where method is omitted.

PR: #50 

Resolves: #49
  • Loading branch information
kwelch authored and kwelch-eb committed Dec 27, 2018
1 parent dce1204 commit 07c5156
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/__tests__/request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ describe('request', () => {
);
});

it('calls should not send "application/json", if method is not passed', async () => {
await request(TEST_URL);

expect(getMockFetch()).toHaveBeenCalledTimes(1);
expect(getMockFetch()).toHaveBeenCalledWith(
TEST_URL,
expect.objectContaining({
credentials: 'same-origin',
headers: {},
})
);
});

it('calls fetch and respects overrides in options', async () => {
await request(TEST_URL, {credentials: 'omit'});

Expand Down
2 changes: 1 addition & 1 deletion src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const _tryParseJSON = (res: Response): Promise<any> => {
*/
export const _fetchJSON = (
url: string,
{headers, method, mode, ...options}: RequestInit = {}
{headers = {}, method = 'GET', mode, ...options}: RequestInit = {}
): Promise<{}> => {
let fetchHeaders = headers as HeadersInit;

Expand Down

0 comments on commit 07c5156

Please sign in to comment.