Convert curl to Elixir

Convert curl commands to Elixir code using HTTPoison. curl2code runs entirely in your browser via WebAssembly — your data stays private. For Ruby, try our curl to Ruby converter. For Go, see curl to Go. Below are ready-to-use Elixir examples.

How to copy curl from your browser

  1. 1

    Open DevTools

    Press F12 or Ctrl+Shift+I to open your browser developer tools.

  2. 2

    Go to the Network tab

    Click the Network tab and perform the action that triggers the HTTP request.

  3. 3

    Copy as cURL

    Right-click the request → CopyCopy as cURL. Then paste it above.

Frequently Asked Questions

What is Elixir HTTPoison?

HTTPoison is the most popular HTTP client for Elixir, built on top of the Erlang hackney library. It provides a clean, functional API for GET, POST, streaming, and async requests. Add to mix.exs deps: {:httpoison, "~> 2.0"}. curl2code uses HTTPoison as the default for Elixir conversions.

HTTPoison vs Req vs Tesla vs Finch — which to use?

HTTPoison is the most established and widely used. Req is newer, batteries-included with retries and auth. Tesla offers middleware architecture like Faraday. Finch is low-level, high-performance for production use. For similar functional approaches, see curl to Clojure or curl to Ruby.

How to handle authentication in Elixir?

Pass headers as a list of string tuples: HTTPoison.get(url, [{"Authorization", "Bearer token"}]). For Basic auth, encode user:pass with Base.encode64/1 and prepend "Basic " to the value. Pattern match the response for {:ok, response} or {:error, reason}. curl2code converts -H and -u flags to idiomatic Elixir.

How to send multipart form data in Elixir?

Use {:multipart, parts} as the body: HTTPoison.post(url, {:multipart, [{:file, path, {"form-data", [{"name", "file"}, {"filename", "doc.pdf"}]}, []}]}). For simple form fields, add {"key", "value"} tuples. curl2code handles -F flags for HTTPoison multipart.

How to handle errors in Elixir HTTP requests?

HTTPoison returns tagged tuples: {:ok, response} or {:error, reason}. Pattern match with case or with: case HTTPoison.get(url) do {:ok, %{status_code: 200}'} -> ... ; {:error, %{reason: reason}'} -> ... end. This is idiomatic Elixir — explicit, exhaustive error handling without exceptions.

How to make concurrent HTTP requests in Elixir?

Use Task.async/1 and Task.await/1: tasks = urls |> Enum.map(&Task.async(fn -> HTTPoison.get(&1) end)) then results = tasks |> Enum.map(&Task.await/1). Elixir's BEAM VM handles thousands of concurrent processes efficiently. For similar concurrency, see curl to Go.

How to set timeouts in Elixir?

Pass options to HTTPoison: HTTPoison.get(url, [], [timeout: 30_000, recv_timeout: 30_000]). timeout is the connection timeout, recv_timeout is the response timeout (both in milliseconds). For retries, wrap in a recursive function with decreasing attempts or use the Req library's built-in retry.

How to use a proxy in Elixir?

Pass proxy option to HTTPoison: HTTPoison.get(url, [], [proxy: {"proxy.host", 8080}]). For authenticated proxies, use proxy_auth: {"user", "pass"}. HTTPoison also supports SOCKS5 proxies via the underlying hackney library. curl2code converts -x flags to Elixir proxy configuration.

How to send a POST request with JSON body in Elixir?

Convert a curl POST command like curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' URL to Elixir using curl2code. The generated code uses HTTPoison.post(url, Jason.encode!(body), [{'Content-Type', 'application/json'}]). curl2code automatically detects -d/--data flags with JSON content and sets the appropriate Content-Type header in the HTTPoison code.

How to add Bearer token authorization in Elixir?

Pass curl -H "Authorization: Bearer YOUR_TOKEN" URL to curl2code and it generates HTTPoison code with the auth header: [{'Authorization', 'Bearer YOUR_TOKEN'}]. curl2code detects Bearer tokens from both -H "Authorization: Bearer ..." and --oauth2-bearer flags. For Basic auth, use -u user:pass.

How to set Content-Type header in Elixir?

curl2code converts curl -H "Content-Type: application/json" URL to HTTPoison code with the proper header: [{'Content-Type', 'application/json'}]. For -d data, curl defaults to application/x-www-form-urlencoded; for -F form uploads, it uses multipart/form-data. curl2code maps each to the correct HTTPoison API.

Useful Links

curl Guides

Convert curl to Other Languages