1.0.1 • Published 2 years ago
rescript-axios v1.0.1
rescript-axios
Axios bindings with reason-promise
Setup
yarn add rescript-axios reason-promise
# or
npm i rescript-axios reason-promise
Add to the bsconfig.json
dependencies :
{
...
"bs-dependencies": ["rescript-axios"]
}
Usage
Basic
Axios.get("http://myapi.com/test", ())
->Promise.Js.toResult
->Promise.mapOk(({data}) => data)
->Promise.tapError(err => {
switch (err.response) {
| Some({status: 404}) => Js.log("Not found")
| e => Js.log2("an error occured", e)
}
})
->ignore
With config
let config = Axios.makeConfig(~baseURL="http://localhost", ())
Axios.patch("/test", ~data=Js.Obj.empty(), ~config, ())
->Promise.Js.toResult
->Promise.tapOk(({data}) => {
Js.log(data["resValue"])
})
->ignore