meafmira / bs-axios Goto Github PK
View Code? Open in Web Editor NEWBucklescript bindings for axios
Bucklescript bindings for axios
I use https://github.com/ryb73/ppx_decco to encode and decode the records and JSONs
To work with Axios I need to do
Axios.postData(url, mytype_encode(response) |> Obj.magic) |> then_(...)
did not try with GET but will be useful to have body and response as JSON?!
What do you think?!
`
25 │ didMount: (self) =>
26 │
27 │ Js.Promise.(
28 │ Axios.get("/user?ID=12345")
29 │ |> then((response) => resolve(Js.log(response##data)))
30 │ |> catch((error) => resolve(Js.log(error)))
31 │ ),
32 │
33 │ /* Js.Promise.( */
This has type:
Js.Promise.t(unit) (defined as Js.Promise.t(unit))
But somewhere wanted:
unit
`
My bsconfig.json
contains axios:
"bs-dependencies": [ "reason-react", "bs-jest", "bs-axios", "bs-css" ]
Example from JS:
axios.defaults.headers.common["Authorization"] = token
Is this possible with the current bindings?
hi @meafmira,
I think axios should be moved to peerDependencies. Especially since it is not used in generated files
redacted output of yarn why axios
yarn why v1.21.1
[1/4] 🤔 Why do we have the module "axios"...?
[2/4] 🚚 Initialising dependency graph...
[3/4] 🔍 Finding dependency...
[4/4] 🚡 Calculating file sizes...
=> Found "[email protected]"
info Has been hoisted to "axios"
info Reasons this module exists
- "workspace-aggregator-43088911-9698-4e6f-aaa9-6d34f43842d4" depends on it
info Disk size without dependencies: "488KB"
info Disk size with unique dependencies: "656KB"
info Disk size with transitive dependencies: "804KB"
info Number of shared dependencies: 3
=> Found "bs-axios#[email protected]"
info This module exists because "bs-axios" depends on it.
info Disk size without dependencies: "412KB"
info Disk size with unique dependencies: "604KB"
info Disk size with transitive dependencies: "752KB"
info Number of shared dependencies: 4
✨ Done in 0.95s.
The lib makes auth
an opaque type in the .rei
file, with no function to actually create it.
Is there a way to intercept 401 responses like with axios?
Here's an example: https://gist.github.com/yajra/5f5551649b20c8f668aec48549ef5c1f
Hi. Is there any way to use a dictionary instead of Js.t
for headers? A scenario where I would either send "header1" or "header2" depending on a condition doesn't seem to be possible to compile, since the type of headers is defined by the first value, and thus the second one would be required to have the same shape.
Axios.makeConfigWithUrl(
~url="https://api.chucknorris.io/jokes/random",
~headers=
checkCondition() ? {"header1": "value1"} : {"header2": "value2"},
(),
);
The error I get is:
Error: This expression has type {. "header2": string}
but an expression was expected of type {. "header1": string}
Is there any way to omit "header1" from the second value? Seems like a dictionary would be a structure that resembles HTTP headers more closely.
Following the example for Headers in the readme:
let headers = Axios.Headers.fromDict(headersDict);
Axios.getc("https://example.com", Axios.makeConfig(~headers, ()));
I noticed that Axios appends default headers, like Accept: application/json, text/plain, */*
. The service I am trying to connect with doesn't accept the Accept
headers, and throws me a 406 -- Not Acceptable error.
Also, when I set the header dict like dict.set("accept", "*/*")
, I noticed that the Accept
header value gets appended with */*
instead of being replace. The Accept
header ultimately looks like:
Accept: application/json, text/plain, */*, */*
.
I noticed that there is a way to remove the default header for the js library:
https://stackoverflow.com/questions/46656474/axios-remove-headers-authorization-in-1-call-only
Is there a way to remove default headers? Or override them?
There is often a need to be more particular about error handling. As explained in the Handling Errors section, Axios allows access to the request/response objects to determine what went wrong. It'd be great if this was a supported feature of bs-axios.
When my account was compromised a spam issue was created in this repo. I sincerely apologize. Cleaning up such issues via script.
I was wondering if it was possible to include the socketPath
parameter in makeConfig?
It is needed for example for communication with the local docker api.
Example code (facebook/react#8883 (comment)):
fetchRepos() {
// cancel the previous request
if (this.source) {
this.source.cancel('Operation canceled due to new request.')
}
// save the new request for cancellation
this.source = axios.CancelToken.source();
this.setState({networkState: 'loading' })
let url = `https://api.github.com/users/${this.props.username}/repos`
axios.get(url, { cancelToken: this.source.token })
.then(response => this.setState({ repos: response.data, networkState: 'loaded' } ))
.catch(error => {
if (axios.isCancel(error)) {
this.setState({ networkState: 'canceled' })
} else {
this.setState({ networkState: 'errored' })
}
});
}
It looks like method
is a reserved keyword in ocaml.
Reason seems to handle this while being compiled to AST and adds a trailing _
, but it breaks syntax highlighting in the remainder of the file which is kind of annoying.
I propose just changing the label to httpMethod
| verb
| httpVerb
open to any other names of course ¯_(ツ)_/¯
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.