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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

data param in transformRequest is undefined #161

Closed
JuoCode opened this issue Nov 24, 2015 · 5 comments
Closed

data param in transformRequest is undefined #161

JuoCode opened this issue Nov 24, 2015 · 5 comments

Comments

@JuoCode
Copy link

JuoCode commented Nov 24, 2015

I want add API endpoint in transformRequest, but data param is undefined 馃槀

const API = axios.create({
  transformRequest: [(data, headers) => {
    console.dir(data);
    console.dir(headers);
    return data;
  }]
});

I use master

@nickuraltsev
Copy link
Member

@JuoCode Can you share the code that sends the request?

@JuoCode
Copy link
Author

JuoCode commented Nov 24, 2015

export function fetchProjects () {
  return dispatch => {
    return API.get('http://example.com/projects')
      .then(response => {
        dispatch({ type: PROJECTS_RECEIVED, payload: response.data });
      });
  };
}

@nickuraltsev
Copy link
Member

transformRequest allows changing the request body (data) and headers. Your code makes a GET request that has no body. That's why data is undefined.

If can try to use interceptors to change other request properties.

API.interceptors.request.use(
  config => {
    // request config can be changed here
    return config;
  }, 
  error => Promise.reject(error)
);

@JuoCode
Copy link
Author

JuoCode commented Nov 24, 2015

Get it! #160 is necessary

@mzabriskie
Copy link
Member

Just released 0.8.0 which includes #160.

@axios axios locked and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants