rescript-axios

1.0.1 • Public • Published

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

Dependents (0)

Package Sidebar

Install

npm i rescript-axios

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

8.01 kB

Total Files

8

Last publish

Collaborators

  • dck