-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.html
68 lines (63 loc) · 3.46 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html>
<head>
<title>curl-to-ruby: Convert curl commands to ruby's net/http</title>
<meta charset="utf-8">
<link rel="stylesheet" href="resources/css/color-brewer.css">
<link rel="stylesheet" href="resources/css/common.css">
</head>
<body>
<header>
<h1>curl-to-ruby</h1>
<h2>Instantly convert <a href="http://curl.haxx.se/">curl</a> commands to <a href="https://www.ruby-lang.org/">Ruby</a>'s <a href="http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/Net/HTTP.html">net/http</a></h2>
<p>
Ruby's <code>net/http</code> is notorious for not having the friendliest API, but it isn't all that bad.
Ruby has great gems like <a href="https://github.com/lostisland/faraday">faraday</a>, but in libraries and small utilities it's better to <a href="http://www.mikeperham.com/2016/02/09/kill-your-dependencies/">kill your dependencies</a> and use what the stdlib provides.
</p>
<p>
This tool turns a curl command into ruby (2.0+) code using <code>net/http</code>. Currently, it knows the following options: <code>-d</code>/<code>--data</code>, <code>-H</code>/<code>--header</code>, <code>-I</code>/<code>--head</code>, <code>-u</code>/<code>--user</code>, <code>-k</code>/<code>--insecure</code>, <code>--url</code>, and <code>-X</code>/<code>--request</code>.
</p>
<p>
There's probably bugs; please <a href="https://github.com/jhawthorn/curl-to-ruby">contribute on GitHub</a>. Based on <a href="https://mholt.github.io/curl-to-go">curl-to-go</a>.
</p>
<p class="examples">
<a href="javascript: useExample('example1')">Simple</a> ·
<a href="javascript: useExample('example2')">Basic Auth</a> ·
<a href="javascript: useExample('example3')">JSON</a> ·
<a href="javascript: useExample('example4')">Complex JSON</a> ·
<a href="javascript: useExample('example5')">Form Data</a>
</p>
</header>
<main>
<script id="example1" language="text/x-shellscript">curl echoip.com</script>
<script id="example2" language="text/x-shellscript">
curl https://api.example.com/surprise \
-u banana:coconuts \
-d "sample data"
</script>
<script id="example3" language="text/x-shellscript">
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer b7d03a6947b217efb6f3ec3bd3504582" -d '{"type":"A","name":"www","data":"162.10.66.0","priority":null,"port":null,"weight":null}' "https://api.digitalocean.com/v2/domains/example.com/records"
</script>
<script id="example4" language="text/x-shellscript">
curl -u "demo:" -X POST -H "Content-Type: application/json" -d '{"array": [1,2,3], "object": {"foo": "bar", "nested": {"baz": true}}}' https://example.com/
</script>
<script id="example5" language="text/x-shellscript">
curl -X POST https://api.easypost.com/v2/shipments \
-u API_KEY: \
-d 'shipment[to_address][id]=adr_HrBKVA85' \
-d 'shipment[from_address][id]=adr_VtuTOj7o' \
-d 'shipment[parcel][id]=prcl_WDv2VzHp' \
-d 'shipment[is_return]=true' \
-d 'shipment[customs_info][id]=cstinfo_bl5sE20Y'
</script>
<textarea id="input" rows="4" placeholder="Paste curl here"></textarea>
<div id="output"></div>
</main>
<footer>
<p>
Protip™: Both chrome and firefox allow <a href="https://daniel.haxx.se/blog/2015/11/23/copy-as-curl/">copying any request as curl</a>.
</p>
</footer>
<script src="resources/js/default.js"></script>
</body>
</html>