svrcekmichal / redux-axios-middleware

Redux middleware for fetching data with axios HTTP client
MIT License
922 stars 96 forks source link

How can I make a post request? #86

Closed nbastoWM closed 6 years ago

nbastoWM commented 6 years ago

I want to use this middleware in a login action but I can't find out how to make a post request.

nbastoWM commented 6 years ago

Answering my question:


export function postLogin(username, password) {
  console.log('>>>>> postLogin');
  let url = config.authentication_url;

  return {
    type: POST_LOGIN,
    payload: {
      request: {
        method: 'post', 
        url: url,
        params: {
          username: username,
          password: password,
          device: Platform.OS === 'ios' ? 'ios' : 'android',
        }
      }
    }
  };
}```
robinvw1 commented 5 years ago

In case anyone has the same question, the answer above is false. params should be data, otherwise it will get sent as query parameters.

return {
    type: POST_LOGIN,
    payload: {
        request: {
            method: 'post',
            url: url,
            data: {
                username: username,
                password: password,
                device: Platform.OS === 'ios' ? 'ios' : 'android',
            }
        }
    }
}
Liqiankun commented 5 years ago

@robinvw1 What about method is 'GET'? 2018-11-26 6 00 53