curl to Ruby
Convert curl commands to Ruby Net::HTTP, HTTParty, or Faraday code.
Library: Net::HTTP (stdlib)Method: POSTHeaders: 2Input Lines: 4Output Lines: 15Output Bytes: 417
Looks like this contains credentials. They are converted in this tab only — not uploaded, and not included in the link that Share or Copy link produces.
curl to Ruby Net::HTTP & HTTParty
Ruby standard library includes Net::HTTP for making web requests. For simpler syntax or specialized middleware, gems like HTTParty and Faraday are widely used. This tool converts curl flags to idiomatic Ruby code across all three libraries.
Built and maintained by Meet Shah · Last updated
What this tool is used for
- Converting an API's curl example into Net::HTTP for a Ruby service.
- Reproducing a captured request inside an existing Ruby client.
- Getting the SSL and header setup right without reading the whole Net::HTTP API.
- Producing a script to run a one-off API call from the command line.
- Checking how a POST body is expressed before wiring it into a class.
Frequently Asked Questions
- Why do I need use_ssl for https URLs?
- Net::HTTP does not infer TLS from the scheme. Net::HTTP.new(host, 443) alone speaks plaintext to a TLS port and fails confusingly — set use_ssl = true, or use Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https').
- Should I use Net::HTTP, Faraday or HTTParty?
- Net::HTTP is in the standard library and needs no gem. Faraday adds a middleware stack and swappable adapters, which suits libraries. HTTParty is the terser choice for scripts. All three end up on the same sockets.
- How do I send JSON?
- request.body = payload.to_json and request['Content-Type'] = 'application/json'. Net::HTTP will not serialise or set the header for you. For form-encoded bodies matching curl's -d, use request.set_form_data(hash) instead.
- Does Net::HTTP follow redirects?
- No — it returns the 3xx response and you must follow it yourself, typically by looping on Net::HTTPRedirection and reading response['location']. Faraday can do it via the FollowRedirects middleware.
- How do I set timeouts?
- open_timeout covers establishing the connection and read_timeout covers waiting for data, both on the Net::HTTP object. Defaults are 60 seconds each — finite, but far longer than most callers want.
- Why prefer Net::HTTP.start over the one-line helpers?
- Because the block form opens one connection and reuses it for every request inside, while `Net::HTTP.get` opens and closes a connection each time. For more than one call to the same host that difference is most of the latency.
Common errors and gotchas
- Forgetting `use_ssl = true`, which silently attempts plain HTTP against an https URL.
- Building the request without a path from the URI, which Net::HTTP needs separately from the host.
- Setting a JSON body without the content-type header, which many APIs then reject.
- Assuming redirects are followed, when Net::HTTP does not follow them by default.
- Expecting a non-2xx to raise, when Net::HTTP returns a response object you must check.
Related Developer Utilities tools
RegExp Tester
Test regular expressions and inspect matches locally.
Regex Visualizer
Visual regex pattern diagram with live match highlighting and capture group annotations.
Subnet Calculator
Compute CIDR subnets, usable hosts, and network ranges.
Cron Parser
Translate cron syntax into plain English.
URL Parser
Break a URL into protocol, host, path, and query parts.
HTML Previewer
Paste HTML and see it rendered live in a safe, sandboxed preview.
HTTP Status Code Reference
Search and look up every HTTP status code and its meaning.
MIME Type Lookup
Find the MIME type for a file extension, or the extensions for a MIME type.