Project

curlify

0.0
The project is in a healthy, maintained state
The gem convert python requests object in curl command.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 2.0
 Project Readme

The gem convert ruby requests(net/http) into curl command.

Installation

To install the gem use bundle or gem, see:

$ gem install curlify

or bundle:

$ bundle add curlify

Usage with faraday

Import curlify and faraday and perform curlify, see:

require 'faraday'
require 'curlify'

request = Faraday.new.build_request(:post) do |req|
  req.url 'http://127.0.0.1'
end

Curlify.new(request).to_curl # "curl -X POST -H 'User-Agent: Faraday v2.9.0'  http://127.0.0.1"

Usage with net/http

Import curlify, uri and net/http and perform curlify, see:

require 'json'
require 'uri'
require 'net/http'
require 'curlify'

uri = URI('https://httpbin.org/post')
request = Net::HTTP::Post.new(uri, { 'content-type': 'application/json' })
request.body = { title: 'Ruby is great :)' }.to_json

Curlify.new(request).to_curl # curl -X POST -H 'content-type: application/json' -H 'accept-encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3' -H 'accept: */*' -H 'user-agent: Ruby' -H 'host: httpbin.org' -d '{"title":"Ruby is great :)"}' https://httpbin.org/post

Performing this curl command, we can see the following result:

{
  "args": {},
  "data": "{\"title\":\"Ruby is great :)\"}",
  "files": {},
  "form": {},
  "headers": {
    "Accept": "*/*",
    "Accept-Encoding": "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
    "Content-Length": "28",
    "Content-Type": "application/json",
    "Host": "httpbin.org",
    "User-Agent": "Ruby",
    "X-Amzn-Trace-Id": "Root=1-64f38ad0-444dbe403f03082e14ba1d62"
  },
  "json": {
    "title": "Ruby is great :)"
  },
  "origin": "xxx.xxx.xx.xx",
  "url": "https://httpbin.org/post"
}