Skip to content

Commit

Permalink
Merge pull request #26 from dabapps/React-Native-GET-request-fix
Browse files Browse the repository at this point in the history
fix for React Native GET requests
  • Loading branch information
JakeSidSmith authored Mar 7, 2019
2 parents b55ef48 + 7a56486 commit 71250d1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dabapps/redux-requests",
"version": "0.5.1",
"version": "0.5.2",
"description": "Library for simple redux requests",
"main": "dist/js/index.js",
"directories": {},
Expand Down
5 changes: 3 additions & 2 deletions src/ts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ export function apiRequest(options: AxiosRequestConfig): AxiosPromise {

// Axios uses a different key for sending data on a GET request
if (options.method === 'GET') {
const { data, ...getConfig } = config;
return axios({
...config,
params: config.data,
...getConfig,
params: data,
});
}
return axios(config);
Expand Down
2 changes: 2 additions & 0 deletions tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ describe('Requests', () => {
const params = (myRequest as any).params;
expect(params.params).toEqual({});
expect(params.headers).not.toBeUndefined();
expect(params).not.toHaveProperty('data');
});

it('should not modify url if not provided', () => {
Expand Down Expand Up @@ -653,6 +654,7 @@ describe('Requests', () => {
const params = (myRequest as any).params;
expect(params.params).toEqual({ a: 1 });
expect(params.headers.b).toBe(2);
expect(params).not.toHaveProperty('data');
});

it('should carry forward our provided data - POST', () => {
Expand Down

0 comments on commit 71250d1

Please sign in to comment.