Convert Curl to Ruby

Convert curl commands to Ruby Net::HTTP code instantly. Free online curl to Ruby converter that handles headers, authentication, and request bodies.

What the generated Ruby code looks like

The converter generates Ruby code that uses Net::HTTP from the standard library. No gems, no Bundler, no Gemfile. The output works with a stock Ruby installation. This makes it ideal for quick scripts, one-off API calls, and environments where adding dependencies is not practical.

The generated code creates a URI object, builds the appropriate request class (Net::HTTP::Get, Net::HTTP::Post, etc.), sets headers and body, and sends the request. The output includes both the response code and the response body.

If you prefer using a higher-level library like Faraday or HTTParty, the generated code serves as a clear reference for the headers, body, and authentication values you need.

How curl flags map to Net::HTTP

Curl flag Ruby Net::HTTP equivalent
-X POST Net::HTTP::Post.new(uri)
-H 'Key: Value' request["Key"] = "Value"
-d '{"key":"val"}' request.body = '{"key":"val"}'
-u user:pass request.basic_auth("user", "pass")
-k http.verify_mode = OpenSSL::SSL::VERIFY_NONE
-b 'cookie=val' Added as request["Cookie"]

SSL and HTTPS handling

The generated code automatically sets http.use_ssl = true when the URL uses HTTPS. If the curl command includes -k or --insecure, the code adds http.verify_mode = OpenSSL::SSL::VERIFY_NONE to skip certificate verification.

For production code, always use SSL verification. The -k flag is useful for development environments with self-signed certificates but should not be used in production.

Authentication in Ruby

Basic auth from -u user:pass maps to request.basic_auth("user", "pass"), which is a built-in method on all Net::HTTP::Request subclasses. This is cleaner than manually encoding the credentials and setting the Authorization header.

Bearer tokens and API keys sent via -H 'Authorization: Bearer token' are preserved as regular headers in the generated code. The converter does not alter authentication headers. What goes in is what comes out.

Net::HTTP vs Faraday vs HTTParty

Net::HTTP is Ruby's built-in HTTP client. It requires no gems, works everywhere Ruby runs, and gives you full control over the request. The downside is its verbose API. Setting up a request takes several lines compared to Faraday or HTTParty.

If your project already uses Faraday or HTTParty, the generated code is still valuable as a reference. The headers hash, body string, and auth values translate directly to any Ruby HTTP library. The converter uses Net::HTTP because it is available without dependencies.

Frequently Asked Questions

How do I convert curl to Ruby?

Paste your curl command into the input field above, select "Ruby," and click Convert. The output uses Net::HTTP from Ruby's standard library and requires no external gems.

Does the generated code work with Rails?

Yes. The generated Net::HTTP code works in any Ruby environment, including Rails applications, Rake tasks, and background jobs. You can paste it directly into a service object or controller action.

Do I need any gems?

No. The output uses only net/http and uri from Ruby's standard library. No Gemfile changes are needed.

Is my curl command sent to a server?

No. All conversion happens in your browser. Nothing leaves your machine.

Can I adapt the output for Faraday?

Yes. The headers hash and body string from the generated code work with any Ruby HTTP library. Replace the Net::HTTP calls with Faraday's conn.post or conn.get using the same values.

Related Free Tools

Give your AI agent a faster, leaner browser

Structured page data instead of raw HTML. Your agent processes less, decides faster, and costs less to run.

Stability detection built in
Fraction of the payload size
Diffs after every action
No credit card required. 1 hour of free runtime included.