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

Add optional config #148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add optional config #148

wants to merge 1 commit into from

Conversation

ShMcK
Copy link

@ShMcK ShMcK commented Jun 21, 2017

Resolves #146.

Allow the ability to overwrite axiosConfig for update & delete resource requests. See PR #146.

This allows the client to make requests at different endpoints.

In the example below, the endpoint for v2 is overwritten with v2.1.

const customConfig = const config = {
...store.getState().api.endpoint.axiosConfig,
baseURL: https://host.com/v2.1/, // rather than v2
};
dispatch(deleteResource(entity, customConfig));
Other axiosConfig properties could be overridden as well, such as host, timeout, etc.

@egeriis
Copy link
Collaborator

egeriis commented Oct 9, 2017

@ShMcK Tests are failing and you've left a console.log statement in the code. Please revise :)

I think it'd be wise if passed "local" config would extend from the default config. E.g. using Object.assign.

@jonathonwalz
Copy link

Since this pull request is superseding #145, could we create the options object like below? Otherwise this will not provide the same functionality. I need a way to pass in data for the meta key.

const options = {
  method: 'POST',
  data: JSON.stringify({
    data: resource
  }),
  ...axiosConfig,
};

@ShMcK
Copy link
Author

ShMcK commented Oct 9, 2017

@egeriis, good idea. I've implemented a config override, rather than config replacement, in 6956c82.

@jonathonwalz, I've also implemented the config override to fit your use case in 6956c82.

I've also cleaned up and squashed commits.

Resolves redux-json-api#146.

overwrites existing config, rather than replacing it, as recommended by @egeriis.
@egeriis
Copy link
Collaborator

egeriis commented Oct 10, 2017

@jonathonwalz Good point! Do you need to set meta for all requests though? In your PR it's per-request?

@ShMcK Good job, will take another look :)

@jonathonwalz
Copy link

Since this hasn't been merged yet, I've run into a use-case where I need to modify the readResource request as well (modify the headers based on request). Would it make sense to include a similar change to allow modifying the axiosConfig for readResource too?

Copy link
Collaborator

@egeriis egeriis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small typo

return (dispatch, getState) => {
dispatch(apiWillDelete(resource));

const { axiosConfig } = getState().api.endpoint;
const axiosConfig = getState().api.endpoint.axios;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seem to be a typo here, endpoint.axios should be endpoint.axiosConfig. If this isn't caught be any tests, we should make that happen 😄

@egeriis
Copy link
Collaborator

egeriis commented Apr 3, 2018

@ShMcK Sorry for letting this stall, I hope you don't mind revisiting this and revising this PR from my review ❤️

@egeriis egeriis mentioned this pull request Apr 13, 2018
@egeriis egeriis changed the base branch from 2.0 to master June 12, 2018 09:49
@zdajani
Copy link

zdajani commented Oct 9, 2019

Just curious about what is happening with this PR I have a use case that really needs these changes and wondering if I can help move it along in any way.

@kayodeadeniyi
Copy link
Contributor

@ShMcK @egeriis I'd like to know if there is something I can do to help move this PR so that it can be merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pass host, namespace into resource changes
5 participants