cURL to Ruby
Convert a curl command to Ruby Net::HTTP
About cURL to Ruby
Writes Ruby code with Net::HTTP from the standard library, so there are no gems to install. The script enables use_ssl for https URLs, maps -u to req.basic_auth, -k to VERIFY_NONE and -F to set_form_data, then prints JSON.parse(res.body). Your cURL command is converted locally in the browser and is not sent to any server.
Category: API.
Frequently asked questions
Do I need any gems to run the Ruby code?
▾
No. It requires only net/http, uri and json from Ruby's standard library, creates the HTTP object with Net::HTTP.new, enables use_ssl for https URLs and sends a request object such as Net::HTTP::Get or Net::HTTP::Post. The last line prints JSON.parse(res.body), so change it if the API returns plain text.
How do -u and -k translate to Net::HTTP?
▾
-u user:pass becomes req.basic_auth 'user', 'pass', and a matching Authorization header line is written too. -k sets http.verify_mode = OpenSSL::SSL::VERIFY_NONE, which disables certificate verification, so use it only with local or test servers.
Why does the Ruby code send -F fields as a URL-encoded form?
▾
Because they are passed to req.set_form_data, which encodes them as application/x-www-form-urlencoded rather than multipart. For multipart requests or file uploads, use req.set_form with 'multipart/form-data' instead; a value like @photo.jpg is copied as plain text.
Does the Ruby code follow redirects when the command uses -L?
▾
No. -L is not translated and Net::HTTP never follows redirects on its own, so check for a 3xx response and request the URL from its Location header if you need that behavior.