After implementing a bunch of HTTP client behaviour modules for different projects and libraries I realised that vast majority of time we don’t need a module, all we need is a function. (Something to keep in mind for other things too.)
Here’s a signature:
f(options) :: {:ok, %{status:, status, headers: headers, body: body}} | {:error, exception}
where options contains :method, :url, :headers, :body and other arbitrary adapter-specific keys.
And then we’d use it like this: Foo.bar(http_request: &MyApp.http_request/1). And if we want to pass options at callsite we’d do: http_request: {&MyApp.http_request/1, receive_timeout: 1000}.
(It is pure accident that with next version of Req, an http client that I’m working on, it’d be: http_request: &Req.request/1. ;))






















