How get request HTTPPoison sending a query string

1.2k views Asked by At

I need get in the api by passing a query string in case the route is:

api/v1/servers/#{server_name}/zones

Query params is rrsets=false and code:

HTTPoison.get!("api/v1/servers/#{server_name}/zones")

How I send with a query string?

1

There are 1 answers

0
Adam Millerchip On BEST ANSWER

The code in your question doesn't even compile - please put more effort to provide a working example next time.

HTTPoison.get!/3 accepts a URL as its first argument, so you can just provide the query string as part of the URL:

HTTPoison.get!("api/v1/servers/#{server_name}/zones?rrsets=false")

If you want to build URL with a dynamic query string, see Idiom to construct a URI with a query string in Elixir:

"api/v1/servers/#{server_name}/zones"
|> URI.parse()
|> Map.put(:query, URI.encode_query(rrsets: false))
|> URI.to_string()