https://github.com/dckt/rescript-axios
Axios bindings with reason-promise
https://github.com/dckt/rescript-axios
Last synced: about 1 month ago
JSON representation
Axios bindings with reason-promise
- Host: GitHub
- URL: https://github.com/dckt/rescript-axios
- Owner: DCKT
- License: mit
- Created: 2022-02-03T13:21:52.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-11T07:43:33.000Z (10 months ago)
- Last Synced: 2025-02-11T13:27:03.890Z (3 months ago)
- Language: ReScript
- Size: 54.7 KB
- Stars: 4
- Watchers: 0
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# rescript-axios
Axios bindings with [@dck/rescript-promise](https://github.com/DCKT/rescript-promise)
## Setup
```bash
yarn add rescript-axios @dck/rescript-promise
# or
npm i rescript-axios @dck/rescript-promise
```Add to the `bsconfig.json` dependencies :
```json
{
...
"bs-dependencies": ["rescript-axios"]
}
```## Usage
### Basic
```rescript
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
```rescript
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
```