meafmira / bs-axios

Bucklescript bindings for axios
71 stars 23 forks source link

How do you access/set defaults? #24

Closed painedpineapple closed 5 years ago

painedpineapple commented 5 years ago

Example from JS:


 axios.defaults.headers.common["Authorization"] = token

Is this possible with the current bindings?

meafmira commented 5 years ago

Sure. There is an example https://github.com/meafmira/bs-axios#headers

painedpineapple commented 5 years ago

@meafmira I did notice that this is how you create headers, but what about updating them in either the axios defaults or on an instance?

painedpineapple commented 5 years ago

I ended up doing the following where instance is an instance of bs-axios:

let setAxiosAuthWith = [%raw {|
  function(axiosInstance, header) {
   | axiosInstance.defaults.headers["Authorization"] = header 
   | /* axios.defaults.common["Authorization"] = header  */
   }
 |}];

let setAxiosAuth = (header: string) => setAxiosAuthWith(instance, header);