Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marcuxyz/curlify
The gem convert ruby requests(net/http) into curl command.
https://github.com/marcuxyz/curlify
curl requests ruby-curl ruby-request
Last synced: about 2 months ago
JSON representation
The gem convert ruby requests(net/http) into curl command.
- Host: GitHub
- URL: https://github.com/marcuxyz/curlify
- Owner: marcuxyz
- License: mit
- Created: 2023-08-31T16:41:19.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-28T10:29:32.000Z (8 months ago)
- Last Synced: 2024-10-25T12:37:53.127Z (about 2 months ago)
- Topics: curl, requests, ruby-curl, ruby-request
- Language: Ruby
- Homepage: https://github.com/marcuxyz/curlify
- Size: 16.6 KB
- Stars: 11
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
The gem convert ruby requests(net/http) into curl command.
## Installation
To install the gem use `bundle` or `gem`, see:
```bash
$ gem install curlify
```or bundle:
```bash
$ bundle add curlify
```## Usage with faraday
Import `curlify` and `faraday` and perform curlify, see:
```ruby
require 'faraday'
require 'curlify'request = Faraday.new.build_request(:post) do |req|
req.url 'http://127.0.0.1'
endCurlify.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:
```ruby
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_jsonCurlify.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:
```bash
{
"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"
}
```