How to convert curl to Ruby
- Paste your curl command (from API docs, a terminal or your browser's dev tools).
- The Ruby code appears instantly, using Net::HTTP. Switch tabs to see other languages.
- Copy the code and run it; no extra packages are needed.
How curl options map to Net::HTTP
| curl | Ruby |
|---|---|
-X POST | Net::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:pass | request.basic_auth("user", "pass") |
-m 10 | open_timeout: 10, read_timeout: 10 |
-k | verify_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.