Open Stratus3D opened 1 year ago
Also running into this when trying to use a MockHTTP module with hammox. The contract is enforced to ensure the Mock returns the same types as what is specified in the behaviour. This means that it is not just about implementing with a different client, but also when using a mock for testing.
I ended up solving this by doing something like this:
defmodule ClientImplementation do
@behaviour Elasticsearch.API
...
@impl true
def request(config, method, url, data, opts) do
# perform actual request here with whatever client you want...
# elasticsearch-library assumes HTTPoison response, so we mimic an HTTPoison
# struct here to keep Dialyzer happy
{:ok, %{status_code: status, body: body}}
end
end
Kind of ugly returning a map with certain values but it kept dialyzer happy in our project so that is what we did.
I'm interested in trying elasticsearch-elixir with Req or Finch for performance reasons. I see there is an
ElasticSearch.API
behavior for the HTTP client modules, but it looks like the types referenced by the behavior are specific toHTTPoison
. Is elasticsearch-elixir designed to be used with other HTTP clients? And if so, can theHTTPoison
specific types in the behavior be removed?Thanks!