Skip to content

curl to Ruby Converter

Paste a curl command and get Ruby code using Net::HTTP from the standard library: no gems needed, with JSON bodies written as Ruby hashes.
require "net/http"
require "uri"
require "json"

uri = URI("https://jsonplaceholder.typicode.com/posts")
request = Net::HTTP::Post.new(uri)
request["Content-Type"] = "application/json"
request["Authorization"] = "Bearer YOUR_TOKEN"
request.body = JSON.dump({
  "title" => "Hello",
  "body" => "From curl",
  "userId" => 1,
})

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
  http.request(request)
end

puts response.code
puts response.body

Converted in your browser. Commands often contain API keys, so nothing is sent anywhere or saved.

How to convert curl to Ruby

  1. Paste your curl command (from API docs, a terminal or your browser's dev tools).
  2. The Ruby code appears instantly, using Net::HTTP. Switch tabs to see other languages.
  3. Copy the code and run it; no extra packages are needed.

How curl options map to Net::HTTP

curlRuby
-X POSTNet::HTTP::Post.new(uri)
-H 'Name: value'request["Name"] = "value"
-d '{"json": true}'request.body = JSON.dump({...})
-F 'name=value'request.set_form([...], "multipart/form-data")
-u user:passrequest.basic_auth("user", "pass")
-m 10open_timeout: 10, read_timeout: 10
-kverify_mode: OpenSSL::SSL::VERIFY_NONE

Tips for the generated Ruby code

  • Check response.is_a?(Net::HTTPSuccess) before using the body.
  • Parse JSON responses with JSON.parse(response.body).
  • Net::HTTP.start keeps one connection open for the block, so put several requests to the same host inside it.

Convert curl to other languages

The same converter writes Python, JavaScript, Node.js (axios), Go and PHP. See the cURL converter for every supported option.

Need an API to try it on? Every API in our list of APIs with no key works with a plain curl command.

Frequently asked questions

Does Ruby's Net::HTTP follow redirects like curl -L?

No. Net::HTTP returns the 3xx response; follow response["location"] yourself, or use a gem like Faraday (with its follow_redirects middleware) or HTTParty, which follows by default.

How do I write the same request with HTTParty?

HTTParty.post(url, headers: {...}, body: payload.to_json, basic_auth: { username:, password: }) sends the same request with less code. Net::HTTP is shown because it needs no gems.

Why does my request fail with OpenSSL::SSL::SSLError?

Usually an outdated certificate store or a server with an incomplete certificate chain. Update your CA certificates rather than using VERIFY_NONE in production.

How do I copy a request as cURL from Chrome?

Open DevTools (F12), go to the Network tab and reload. Right-click the request, choose Copy, then Copy as cURL (bash). Paste it here. Chrome's Windows (cmd) format works too.

Is it safe to paste commands that contain API keys?

Yes. The conversion runs entirely in your browser; nothing you paste is sent to a server, logged or saved. Still, rotate any key you've shared publicly.

More free developer tools