Linux Network Tools - cURL

2017-06-13
linuxnetworking

cURL (see URL)

curl is a command line tool that uses libcurl to make URL requests. libcurl is a portable library that works across many platforms. It supports cookies, FTP, HTTP, HTTPS, proxy tunneling, etc.

Quick Reference

$ curl -i -X GET http://localhost:7000/users

$ curl -i -H "Content-Type: application/json" -d '{"username":"user","password":"password"}' -X POST http://localhost:7000/api/login

$ curl -i -d '{"username":"user","password":"password"}' -X POST http://localhost:7000/users

$ curl -i -d '{"username":"user","password":"password"}' -X PUT http://localhost:7000/users/1

$ curl -X DELETE http://localhost/users/1

Flags

  • -#, --progress-bar: display a simple progress bar.

  • -b, --cookie <file-or-pairs>: curl -b "X=1; Y=Yes" http://localhost:7000/users.

  • -d, --data <data>: request body.

  • -F, --form <name=content>: form data curl -F "user=james;type=text/foo" http://localhost:7000/users.

  • -g, --globoff: can include the {}[] characters in the URL.

  • -H, --header <header>: headers included with the request.

  • -i, --include: include HTTP headers in the output.

  • -I, --head: fetch headers only

  • -L, --location: if a header and 3XX response code is received, repeat the query to the new location.

  • -v, --verbose: provide more information.

  • -X, --request: DELETE, GET, HEAD, OPTIONS, POST, PUT. If not included will default to GET.

Examples

GET

We can make a simple GET request by typing the address and port after curl. curl assumes the request is GET if no explicit request type is given.

We can test it out by listening to port 7000 with nc, then make a connection with curl and type something in the command line window where nc is running.

POST

Login request with JSON.

Make authenticated request.

Login request for a GraphQL API.

References