The behavior of a simple HTTP Client in Elixir
I maintain a hex Package that uses HTTP requests.
Sep 16, 2020 Publish documentation for release 0.2.1 Sep 16, 2020 Publish release 0.2.1 Sep 10, 2020 Publish…
Currently, this package is supposed to use HTTPoison as the HTTP Client, but I wanted to know how to specify the HTTP Client more flexibly.
My competent colleague taught me the ExAws approach.
This is to define a Behavior that matches the interface you want to use in your application, and inject an implementation of it.
I would like to avoid defining a similar Behavior every time I develop a package that utilizes the HTTP Client, as it would be tedious.
Looking at the code above, ExAws Behavior is very versatile.
However, I would like to avoid the need for ExAws just to use the Behavior from the viewpoint of package dependence.
So I released only Behavior, a simple HTTP client, as a standalone package.
Sep 14, 2020 Publish documentation for release 0.1.1 Sep 14, 2020 Publish release 0.1.1 Sep 13, 2020 Publish…
Here, the “request” function is defined as callback.
Scratcher.HttpClient - scratcher v0.1.1
Module used as Behavior of HTTP Client. It respects the design of the ex_aws HTTP client module…
I’m adding an HTTP header to the ExAws.Request.HttpClient response, It’s almost the same.This package is independent because it does not implement a specific HTTP Request.
The developer can call HTTP Request within our application/module by following the steps below.
- Use a module that already implements `Scratcher.HttpClient` as Behavior, or implement a module that uses the HTTP Client that you want to use.
- Specify the module in Config.
- The module that wants to send HTTP request can use the HTTP Client module obtained from Config.
Of course, you can use Scratcher.HTTPClient as a Behavior even if you want to mock an HTTP Request.
Then, referring to ExAWS, I created a package that implements this in Hackney.
I plan to prepare a package with a minimum implementation for other famous HTTP Clients (HTTPoison, HTTPotion…).
I hope this package will be used by developers who are as troubled with handling HTTP Clients as I am. For feedback, please use the Issue or Pull Request on Github.