Linux Network Tools - cURL

June 13, 2017

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




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.

$ curl localhost:7000

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.

$ nc -l 7000
GET / HTTP/1.1
Host: localhost:7000
User-Agent: curl/7.47.0
Accept: */*

Hello cURL!
$ curl localhost:7000
Hello cURL!


Login request with JSON.

$ curl -H "Content-Type:application/json"  -d '{"email":"",password:"password"}"' -X POST http://localhost:3000/api/login

Make authenticated request.

$ curl -H "X-Auth-Token: 123abc" -H "X-User-Id: 112233" -H "Content-Type:application/json"  -d '{"email":"",password:"password"}"' -X POST http://localhost:3000/api/users

Login request for a GraphQL API.

$ curl -H "Content-Type:application/json"  -d '{"query":"mutation{login(email:"",password:"password"){token,user}}"' -X POST http://localhost:3000/graphql