meafmira / bs-axios

Bucklescript bindings for axios
71 stars 23 forks source link

Allow Node.js HTTP/HTTPS agent to be provided #20

Closed phillipj closed 5 years ago

phillipj commented 5 years ago

Hi there! Thanks a bunch for writing and sharing this binding 👌

In some edge case scenarios, it's important to be able to configure the underlying Node.js HTTP/HTTPS agent used when perform outgoing requests. Examples are adjusting keep alive sockets, various TLS/SSL options etc.

These changes allows those agents to be created and provided whenever requests are sent.

Here's a trivial example of allowing insecure HTTPS requests:

let httpsAgent =
  Axios.Agent.Https.(config(~rejectUnauthorized=false, ()) |> create);

Axios.getc(
  "https://insecure-example.com",
  Axios.makeConfig(~httpsAgent, ()),
);

Worth mentioning that I decided to create a new file (axios_agent.re) for these agent related things, because I noticed the require('http') and require('http') in top of the generated JavaScript output when put inside the already existing axios.re file. As I assume this binding could also be used clientside, those require statements didn't seem like the way to go.

Don't hesitate to point out even the most basic type of flaws with this implementation as I'm definitely a ReasonML rookie.

meafmira commented 5 years ago

Thank you!

  1. Could you make Axios_agent also accessible through Axios.Agent?
  2. Could you update readme and examples too?
phillipj commented 5 years ago

Absolutely, fixed and force pushed back again.

Thanks for the lightning quick response!

meafmira commented 5 years ago

@phillipj thanks! Publish to npm as 0.42.0. Release here - https://github.com/meafmira/bs-axios/releases/tag/v0.0.42