Convert curl to Ruby

curl2code converts curl commands to Ruby code using the standard net/http library. Everything runs locally in your browser via WebAssembly for complete privacy. If you prefer Python, check our curl to Python converter. For Elixir, see curl to Elixir. Below are practical Ruby 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 Ruby net/http?

Ruby's net/http is the standard library HTTP client included with every Ruby installation. It handles GET, POST, multipart uploads, SSL, and custom headers. No gem installation needed. curl2code also supports HTTParty, a popular gem that simplifies common HTTP patterns with a clean, declarative API.

net/http vs HTTParty vs Faraday — which should I use?

net/http is built-in and dependency-free — great for simple tasks and scripts. HTTParty provides a clean DSL with automatic JSON parsing. Faraday offers middleware, adapter patterns, and the most flexibility. For similar scripting simplicity, see our curl to Python converter or curl to PHP.

How to handle authentication in Ruby?

With net/http: request["Authorization"] = "Bearer token". For Basic auth: request.basic_auth("user", "pass"). HTTParty uses headers: { "Authorization" => "Bearer token" } or basic_auth: { username: "user", password: "pass" }. curl2code handles both -u and header flags.

How to send multipart form data in Ruby?

With net/http, use the multipart-post gem or construct the multipart body manually using Net::HTTP::Post with boundary strings. HTTParty simplifies this with body: { file: File.open("path") }. curl2code converts -F flags for both library variants.

How to handle HTTP errors in Ruby?

With net/http, check response.is_a?(Net::HTTPSuccess) or use response.value which raises on non-2xx status. HTTParty returns a response object with .success? and .code methods. For persistent connections, rescue Errno::ECONNREFUSED and Net::ReadTimeout.

How to make concurrent HTTP requests in Ruby?

Ruby's standard library is synchronous. Use Thread.new { ... } for basic concurrency or the concurrent-ruby gem for thread pools. For async I/O, use async-http with the Async gem. Typhoeus provides parallel request queuing. For built-in async support, see curl to Elixir.

How to set timeouts in Ruby?

With net/http: http.open_timeout = 10 (connection) and http.read_timeout = 30 (response). HTTParty accepts timeout: 30 option. These map to curl's --connect-timeout and --max-time. Always set timeouts to avoid indefinitely hanging requests.

How to use a proxy in Ruby?

With net/http: Net::HTTP.new(host, port, proxy_host, proxy_port). Or set http_proxy and https_proxy environment variables — Ruby respects these automatically. HTTParty uses http_proxy: 'http://proxy:8080' option. curl2code converts -x flags to the right Ruby syntax.

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

Convert a curl POST command like curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' URL to Ruby using curl2code. The generated code uses Net::HTTP.post(uri, data.to_json, 'Content-Type' => 'application/json'). curl2code automatically detects -d/--data flags with JSON content and sets the appropriate Content-Type header in the net/http code.

How to add Bearer token authorization in Ruby?

Pass curl -H "Authorization: Bearer YOUR_TOKEN" URL to curl2code and it generates net/http code with the auth header: req['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 Ruby?

curl2code converts curl -H "Content-Type: application/json" URL to net/http code with the proper header: req['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 net/http API.

Useful Links

curl Guides

Convert curl to Other Languages