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: 
You can use the bracket notation with the ternary operator to use post or put depending on condition. You can also use the ternary operator to pass the config if the condition is met, and otherwise pass an empty object as config.

```
axios[condition ? 'put' : 'post'](`${ROOT_URL}/company`, data, condition ? config : {})

```
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(...)

```