Registry / devops / bs-axios

bs-axios

JSON →
library0.0.43jsnpmunverified

Bucklescript (ReScript) bindings for Axios HTTP client. Version 0.0.43, last updated in 2020, uses OCaml/ReasonML syntax. No longer actively maintained; Bucklescript has been superseded by ReScript/bs-platform. Provides typed bindings for Axios get, post, all, instance creation, error handling, and headers. Requires bs-platform ^7.1.0.

npm install bs-axios
INSTALL
IMPORT
SIG · BS-AXIOS
B
bs-axios
devopsjavascriptv0.0.43
harness data pending
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))) );
Debug
Known issues
deprecatedBucklescript has been renamed to ReScript. This package targets bs-platform, not ReScript.
fix
Consider using rescript-axios or migrating to a native JS fetch with rescript-promise.
affects: all
deprecatedPackage is unmaintained (last update 2019-2020). No browser support documentation.
fix
Do not use for new projects. Use rescript-axios or a different HTTP library.
affects: all
gotchaAxios.all2 returns a tuple of two responses, not an array. all (variadic) is not available.
fix
Use all2 for exactly two requests; use promise chaining for more.
affects: all
gotchaError handling requires an external identity cast to convert Js.Promise.error to Js.t
fix
Define: external promiseErrorToJsObj : Js.Promise.error => Js.t('a) = "%identity";
affects: all
Errors
Common errors & fixes
Unbound module Axios
bs-axios not added to bs-dependencies or not installed.
fix
Add "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).
fix
Use 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.
fix
Use Axios.all2((requestA, requestB)) for exactly two promises.
Upgrade
Version history
0.0.43latest on npm
Audit
Dependencies
bs-platformrequiredPeer dependency required for Bucklescript compilation
Agent activity
26 hits · last 30 days
node
24
Amazon
1
Resources
bs-axios — npm install bs-axios · libregistry