Curl is a command line tool for transferring data with a url syntax. Most systems should have curl installed. Open up terminal on OS X or command prompt on Windows and type in
curl. There are parts of the OAuth process that were not intended for direct human interaction, such as exchanging the code from the Provider for an access_token. Because of this, it can be easier to use
curl to talk to a server directly instead of using a web browser.
With curl, we’re able to arbitrarily add parameters to our requests and send using arbitrary HTTP verbs (GET/POST/DELETE) that are difficult to simulate in the browser. If you need to
POST data to a url, doing so with curl is much easier than constructing a form for testing.
On the command line, you should be able to get get help by typing
man curl if your system supports man pages. Below are some simple and common use cases.
You can get the entire contents of a web document by simply calling curl with that url:
$ curl https://www.google.com
You can ask for the headers of a request by adding the
-I flag to a curl command:
$ curl https://www.google.com -I
The response may look something like this:
HTTP/1.1 200 OK Expires: -1 Cache-Control: private, max-age=0 Content-Type: text/html; charset=ISO-8859-1 Server: gws X-XSS-Protection: 1; mode=block X-Frame-Options: SAMEORIGIN Transfer-Encoding: chunked
You can set a request header by using
-H. For example, if you wanted to send an access_token in a header, you could issue this request (assuming your access token is ‘9693accessTokena7ca570bbaf’):
$ curl -H "Authorization: token 9693accessTokena7ca570bbaf" "https://opro-demo.herokuapp.com/oauth_tests/show_me_the_money"
You can specify the type of request you make in curl (GET, POST, PUT, DELETE, etc.) by using
-X. For example, if you wanted to POST to the /products path at http://opro-demo.herokuapp.com/, you could do so like this:
$ curl -X POST http://opro-demo.herokuapp.com/products
Hurl is an open source browser-based
curl implementation. If you’re going to do quite a few curl requests, using it can be easier than the command line.