Skip to content
ZeroServer.tools

curl to Elixir

Convert curl commands to Elixir HTTPoison HTTP client code. Supports headers, request body, authentication, and all common HTTP methods.

Presets:
HTTP Method
POST
Headers Detected
2
Body Bytes
44 B
Elixir Size
14 lines (301 B)

Looks like this contains credentials. They are converted in this tab only — not uploaded, and not included in the link that Share or Copy link produces.

About curl to Elixir conversion

Elixir's HTTPoison library is a popular HTTP client built on Hackney. This converter maps curl flags to HTTPoison calls:-H becomes a headers list of tuples, and -d becomes the body argument. GET and POST use the convenience functions while other HTTP methods use HTTPoison.request/4. Add {:httpoison, "~> 2.0"} to your mix.exs dependencies.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Converting an API's curl example into HTTPoison code.
  • Reproducing a captured request inside an existing Elixir client.
  • Getting the header list and body form right.
  • Producing a snippet for an IEx session or a Mix task.
  • Checking how options are passed alongside headers.

Frequently Asked Questions

Which HTTP client is current?
Req is the modern default — batteries included, decodes JSON automatically, retries by default. Finch is the low-level pooled client Req builds on. HTTPoison and Tesla are still widespread in older codebases.
How do I handle the result?
Pattern match the tagged tuple: {:ok, %Req.Response{status: 200, body: body}} versus {:error, exception}. A 404 arrives as :ok with status 404 — it is a successful HTTP exchange, not a transport failure.
Does it parse JSON for me?
Req does, based on the response content type, so body is already a map. HTTPoison does not — you get a raw binary and must call Jason.decode!/1 yourself. This is the main difference when porting between the two.
Do I need to start anything first?
HTTPoison requires its application to be started, which Mix normally handles. Req and Finch expect a supervised Finch pool for production use; the convenience API starts a default one, which is fine for scripts but not for throughput.
How do I set a timeout?
Req takes receive_timeout and connect_options: [timeout: ...]. HTTPoison takes :timeout (connect) and :recv_timeout (response) as options — two separate values, and the naming difference catches people out.
Why does a failed request return a tuple rather than raise?
Because Elixir treats an expected failure as a value — `{:ok, response}` or `{:error, reason}` — so the caller must match on it. Libraries offer a bang variant that raises, but pattern matching is the idiomatic path and makes the failure case visible.

Common errors and gotchas

  • Forgetting HTTPoison depends on hackney being started, which a bare script may not do.
  • Pattern-matching only on `{:ok, response}` and crashing on the error tuple.
  • Passing a map as the body without encoding it, since HTTPoison expects a binary.
  • Assuming a non-2xx is an error tuple, when it arrives as `{:ok, %{status_code: 404}}`.
  • Omitting the recv timeout, whose default is short enough to bite on slow endpoints.

Related Developer Utilities tools

Private & free — this tool runs entirely in your browser.

IndieKitShip your Next.js startup in days.affiliate