Just something for fun I whipped up. This showcases how easy it is to work with an API (Application Programming Interface). The idea is that an application should be able to "share" and "receive" content with other applications.
For example, Instagram ought to be able to post to Facebook for you. An API is simply the process an application asks you to use.
The link to the cat API documentation is here: http://thecatapi.com/docs.html
You can see that I can use the code
api/images/get?format=xml&results_per_page=20 which ought to allow me to:
- Request a random cat picture
- Receive the information in XML format
- Receive 20 images
This is a very commonly formatted request. It consists of the type of request and the parameters of the request.
The type of request is
GET and the parameters are
There are two types of requests: GET and POST. The main differences are that GET requests can be bookmarked and publically seen in the address bar, while a POST request cannot. It is a general rule that GET requests be used for frequently accessed searches and POST requests be reserved for less-used and more secure events like submitting forms or passwords.
You'll notice the parameters have two values on either side of the equals operator. The first word is considered the
key, while the second word is considered the
value. The API documentaiton lets you know the various keys which can be used and you get to supply a valid value.
This is how applications talk to each other!
But, since you are paying good money to host your application, you wouldn't want anyone to abuse your API. The solution to this problem is requiring developers to sign up and receive a secret API key. This key is sent as a parameter to most APIs to track and restrain usage and even fairly charge users if they go over a certain limit of requests.