Question: generally in Javascript, say I have got this code:

```
return (dispatch) => {
    return axios.post(`${ROOT_URL}/company`, data).then(companyResponse => {

    }).catch(error => {
        throw (error);
    });
};

```

Now, in some cases I want to call the "post" method with some parameters (as written above) and in other cases I'd like to use "put" with different params.
Something like this:

```
// Pseudo code
if(some condition){
    // use this: axios.put(`${ROOT_URL}/company`, data, config)
}
    // use this: axios.post(`${ROOT_URL}/company`, data)
}

```

What is the best practice for doing that?

Answer: 
> 
> Something like this
> 
> 
> 

Yes, exactly like this. Remember that promises are just values, you can pass them around and store them in variables or make them the results of expressions.

```
return (dispatch) => {
    var promise;
    if (some condition)
        promise = axios.put(`${ROOT_URL}/company`, data, config);
    else
        promise = axios.post(`${ROOT_URL}/company`, data)
    return promise.then(companyResponse => {
        …
    });
}

```

Or use the conditional operator:

```
return (dispatch) => {
    return (some condition
      ? axios.put(`${ROOT_URL}/company`, data, config);
      : axios.post(`${ROOT_URL}/company`, data)
    ).then(companyResponse => {
        …
    });
}

```
You can also use axios config object to specify method:

```
const method = condition ? 'put' : 'post' // ternary operator
axios({ method, url: `${ROOT_URL}/company`, data })
  .then(...)
  .catch(...)

```