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

Allow to pass encoded params. #134

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

danhper
Copy link

@danhper danhper commented May 8, 2016

I am trying to send a request with a query as follow:

http://example.com?foo[]=1&foo[]=2

which is to encode easy using Plug.Conn.Query.encode, as %{foo: [1, 2]} yields the correct result.
However, it seems to be impossible to pass an already encoded query to HTTPoison,
as URI.encode_query fails.
Of course, we can append directly to the URL, but as the params option already exists,
I think it would be nicer to support this case as well.

This patch keeps the previous behavior when the query is not a binary, and avoid
trying to reencode it when it is already a binary.

Thank you.

@edgurgel
Copy link
Owner

edgurgel commented May 8, 2016

I'm not sure if this change is desirable. If you already encoded the query params why would you pass it to the params option? The only real "benefit" is that HTTPoison would add the ? right?

@danhper
Copy link
Author

danhper commented May 25, 2016

Sorry for the delay!

The only real "benefit" is that HTTPoison would add the ? right?

That would be one benefit, but for me the major benefit is to keep things consistent.
I often wrap my calls in the following way

defmodule MyHTTPClient do
  use HTTPoison.Base

  def get_something(query) do
    get("/path/to/something", [], params: query)
  end
end

and I would rather have HTTPoison do the right thing with my query
than handle it at the application level.

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

Successfully merging this pull request may close these issues.

None yet

2 participants