Skip to content
koducathome

cURL to Ruby Converter

Convert curl commands to Ruby code using Net::HTTP or HTTParty. Paste a command and the Ruby snippet appears instantly — everything runs in your browser.

How to use this tool

Steps for using the cURL to Code.

  1. Copy a curl command — from API documentation, or from your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
  2. Paste it into Enter cURL command. The Ruby Net::HTTP code appears instantly; other Ruby libraries (HTTParty) are in the tabs above the code.
  3. Set up: Nothing to install — it's in the standard library.
  4. Run it: Run the script with ruby request.rb. Replace placeholders such as YOUR_TOKEN first, and check any notes under the editors for curl options that have no Net::HTTP equivalent.

Example

GET with headers → Ruby Net::HTTP

curl command
curl 'https://api.example.com/v1/users?page=2' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer YOUR_TOKEN'
Ruby Net::HTTP
require 'net/http'
require 'uri'

uri = URI('https://api.example.com/v1/users?page=2')
request = Net::HTTP::Get.new(uri)
request['Accept'] = 'application/json'
request['Authorization'] = 'Bearer YOUR_TOKEN'

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

Common use cases

  • Scripts without gems
  • Rails apps that avoid extra dependencies

Converting curl to Ruby Net::HTTP

Net::HTTP is Ruby's built-in HTTP client.

The converter reads the curl command the way curl does — the method (-X), headers (-H), request bodies (-d, --data-raw, --json, -F), query strings, basic auth (-u) and cookies — and writes the equivalent Net::HTTP code. Options that have no Net::HTTP equivalent are listed under the editors rather than silently dropped.

Other libraries for Ruby, each with its own page: HTTParty.

Limitations

  • The code is a starting point: add timeouts, retries and error handling for production use.
  • Secrets in the curl command are copied into the code — move them to environment variables before committing.

Frequently asked questions

Why use_ssl?

Net::HTTP only uses HTTPS when told to; the code turns it on for https:// URLs.

Is there a simpler Ruby option?

Yes — HTTParty gives a shorter API.

Is my curl command sent to a server?

No. The conversion runs entirely in your browser, so tokens and passwords in the command never leave your device. Still, replace real secrets before sharing the generated code.