├── LICENSE
├── README.md
├── cheat-sheet.md
└── cheat-sheet.pdf
/LICENSE:
--------------------------------------------------------------------------------
1 | See http://creativecommons.org/licenses/by-sa/4.0/ for the details of how this work is licensed.
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | curl-api-cheat-sheet
2 | ====================
3 |
4 | A curl Cheat Sheet tailored for playing with APIs. Please feel free to submit Pull Requests, or copy and/or modify and share on your own.
5 |
6 | 
cURL API User's Cheat Sheet by Ted M. Young is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
7 |
--------------------------------------------------------------------------------
/cheat-sheet.md:
--------------------------------------------------------------------------------
1 | # Basic GET
2 |
3 | ## GET a single resource via its URI
4 |
5 | Default operation is a GET:
6 |
7 | curl http://api.example.com:8080/statuses/1234
8 |
9 | ## GET multiple resources where IDs are in a range
10 |
11 | Use square brackets with a dashed range:
12 |
13 | curl http://api.example.com:8080/items/[1230-1234]
14 |
15 | ## GET multiple resources where IDs aren't in a range
16 |
17 | Use curly braces with comma-delimited strings:
18 |
19 | curl http://api.example.com:8080/products/{abc,def,ghi}/status
20 |
21 | # Using HTTP Headers
22 |
23 | ## Accept only the application/json content-type
24 |
25 | Use the header option: `-H` or `--header`
26 |
27 | curl -H 'Accept: application/json' http://api.example.com:8080/items/1234
28 |
29 | ## Add multiple headers
30 |
31 | Use multiple `-H` options:
32 |
33 | curl -H 'Accept: application/json' -H 'Accept-Encoding: gzip' http://api.example.com:8080/products/a1b2c3ef/status
34 |
35 | Note: the output from this is likely to be unreadable, because it's gzipped!
36 |
37 | More likely you'd use this with ETags:
38 |
39 | curl -H 'Accept: application/json' -H 'If-None-Match: "1cc044-172-3d9aee80"'
40 | http://api.example.com:8080/products/a1b2c3ef/status
41 |
42 | ## Show the network and HTTP "conversation"
43 |
44 | Use the verbose option: -v or --verbose
45 |
46 | curl -v -H http://api.example.com
47 |
48 | # POST and PUT
49 |
50 | ## POST data to a URI
51 |
52 | To send data to the server, you use either POST or PUT, depending on what the API requires. To do a POST, you simply use the `-d` (`--data`) with some content:
53 |
54 | curl -d "name=Ted" http://api.example.com:8080/customers
55 |
56 | Note that this uses `application/x-www-form-urlencoded` as the Content-Type, i.e., as if it was submitted by an HTML Form. You can use multiple `-d` options, which will be combined, e.g., these two commands produce the same content:
57 |
58 | ~~~~
59 | curl -d "first=Ted" -d "last=Young" http://api.example.com:8080/customers
60 | ~~~~
61 |
62 | ~~~~
63 | curl -d "first=Ted&last=Young" http://api.example.com:8080/customers
64 | ~~~~
65 |
66 | If you want to send JSON, you'll need to specify the Content-Type explicitly using the `-H` (header) option:
67 |
68 | curl -d '{"name": "Ted"}' -H 'Content-Type: application/json' http://api.example.com:8080/items
69 |
70 | ## PUT data to a URI
71 |
72 | If you need to use the PUT method, you'll need to override the method with the `-X` (`--request`) option:
73 |
74 | curl -X PUT -d '{"name": "Ted"}' -H 'Content-Type: application/json' http://api.example.com:8080/items/1234
75 |
--------------------------------------------------------------------------------
/cheat-sheet.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tedyoung/curl-api-cheat-sheet/574e2a58a68a1b56eb6891ca0b12b2d056b09f12/cheat-sheet.pdf
--------------------------------------------------------------------------------