Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Axios
✓ open Axios;
✗ import Axios from 'bs-axios'
Bucklescript uses open/modules, not ES imports. Must add bs-axios to bs-dependencies in bsconfig.json.
Axios.get
✓ Axios.get("/endpoint")
✗ Axios.get("/endpoint", {})
Second argument is optional config; if using just URL, omit second arg.
Axios.makeConfig
✓ Axios.makeConfig(~baseURL="https://example.com", ())
✗ Axios.makeConfig({baseURL: "..."})
Uses ReasonML labeled arguments (~) and unit () for required fields. JavaScript object syntax not valid.
Instance.create
✓ let inst = Axios.Instance.create(makeConfig(~baseURL="https://example.com", ()))
✗ let inst = Axios.create({baseURL: "..."})
Must open Axios or prefix Instance module. Config uses ReasonML syntax.
Axios.all2
✓ Axios.all2((Axios.get("/a"), Axios.get("/b")))
✗ Axios.all([Axios.get("/a"), Axios.get("/b")])
all2 is for exactly two promises. all (variadic) does not exist in this version.
Shows GET, POST, instance creation, and promise handling in Bucklescript with ReasonML syntax.
// Ensure bsconfig.json has "bs-axios" in "bs-dependencies"
// Then in a ReasonML file:
open Axios;
Js.Promise.(
Axios.get("/user?ID=12345")
|> then_((response) => resolve(Js.log(response##data)))
|> catch((error) => resolve(Js.log(error)))
);
// Post with data
let user = {
"username": "michel",
"password": "12345678"
};
Js.Promise.(
Axios.postData("/auth", user)
|> then_((response) => resolve(Js.log(response##data)))
|> catch((error) => resolve(Js.log(error)))
);
// Creating an instance
let inst = Instance.create(makeConfig(~baseURL="https://example.com", ()));
Js.Promise.(
Instance.get(inst, "/")
|> then_((resp) => resolve(Js.log(resp##data)))
);
Errors
Common errors & fixes
Unbound module Axios
bs-axios not added to bs-dependencies or not installed.
fixAdd "bs-axios" to "bs-dependencies" in bsconfig.json and run npm install.
The variant create is not of the type 'a
Using incorrect config syntax (JS object instead of Reason labeled args).
fixUse makeConfig(~baseURL="...", ()) instead of {baseURL: "..."}. This expression has type Js.Promise.t('a) but an expression was expected of type Js.Promise.t('b)
Using Axios.all with array instead of all2 with tuple.
fixUse Axios.all2((requestA, requestB)) for exactly two promises.
Audit
Dependencies
bs-platformrequiredPeer dependency required for Bucklescript compilation