cURL to Ruby
Paste a curl command and get a runnable Ruby script using net/http from the standard library — no gems required.
cURL to Ruby converts entirely in your browser. Commands containing tokens or credentials are never uploaded.
Open cURL to Python
cURL to Ruby के बारे में
API documentation is written in curl and applications are written in Ruby, so the same translation gets done by hand over and over. This converter parses the flags that matter — the method, headers, data, basic auth and the query handling behind -G — and emits a script built on net/http, which ships with Ruby and needs no gems installed. A JSON body is rendered as a hash and passed through JSON.generate rather than pasted in as an opaque string, so it is easy to edit before running, and a -u flag becomes a basic_auth call instead of a hand-rolled Authorization header. The result is code a Ruby developer would recognise as their own.
विशेषताएँ
- net/http from the standard library, so nothing needs installing
- Headers, request body, query strings and basic auth all carried over
- JSON bodies rendered as an editable Ruby hash
- basic_auth used instead of a hand-built Authorization header
- Non-standard verbs handled through Net::HTTPGenericRequest
- TLS switched on automatically for https URLs
- Warnings for curl flags with no Ruby equivalent
- Download the result as a .rb file
- Conversion happens entirely in your browser
cURL to Ruby का उपयोग कैसे करें
- Copy the curl command from the API documentation
- Paste it into the left pane
- Read the generated Ruby on the right
- Copy it, or download it as a .rb file
उदाहरण
इनपुट
curl -X POST https://api.example.com/users -H "Content-Type: application/json" -d '{"name":"Ada"}'
आउटपुट
request = Net::HTTP::Post.new(uri)
request["Content-Type"] = "application/json"
request.body = JSON.generate({ "name" => "Ada" })
The body arrives as a hash you can edit, not a quoted blob.
सामान्य त्रुटियाँ और समस्या निवारण
- The script raises an SSL verification error. — That usually means a self-signed or internal certificate. Point OpenSSL at your CA bundle rather than disabling verification — curl's -k flag has no safe equivalent and is deliberately not translated.
- The API rejects the request body. — Check the Content-Type header survived the copy. net/http does not set one for you, so a JSON payload sent without the header is often parsed as form data by the server.
- A redirect is not followed. — curl's -L has no direct equivalent — net/http returns the 3xx response and leaves the decision to you. Check for Net::HTTPRedirection and re-request the Location header if you need it.
अक्सर पूछे जाने वाले प्रश्न
- Does the generated Ruby need any gems?
- No. It uses net/http, uri and json, all of which ship with Ruby, so the script runs on a stock installation with nothing to install.
- Why use net/http rather than Faraday or HTTParty?
- Standard library code runs anywhere without a Gemfile, which makes it the safest default for a snippet you are pasting into an unfamiliar project. Porting it to a gem afterwards is straightforward — the headers and body are already separated out.
- How is basic auth handled?
- A -u flag becomes a request.basic_auth call with the username and password as separate arguments. That is the idiomatic form, and it avoids the Base64 encoding step that a hand-built Authorization header needs.
- What happens with an unusual HTTP verb?
- Verbs without a Net::HTTP class, such as PURGE, are emitted through Net::HTTPGenericRequest with the method name as a string, which handles anything a server accepts.
- Does my curl command leave my machine?
- No. Parsing and code generation happen in your browser, so a command containing a live API token never leaves your machine.
संबंधित टूल
सभी ArrayKit टूल