Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different HTTP Client? #112

Open
Stratus3D opened this issue Mar 20, 2023 · 2 comments
Open

Different HTTP Client? #112

Stratus3D opened this issue Mar 20, 2023 · 2 comments

Comments

@Stratus3D
Copy link

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 to HTTPoison. Is elasticsearch-elixir designed to be used with other HTTP clients? And if so, can the HTTPoison specific types in the behavior be removed?

Thanks!

@Ivor
Copy link

Ivor commented Nov 6, 2023

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.

@Stratus3D
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants