Playing around with REST APIs

Based on the following video: https://www.youtube.com/watch?v=7YcW25PHnAA

Just try the following:
https:/graph.facebook.com/youtube
You get JSON back, which contains like the number of likes

Now use parameters:
https:/graph.facebook.com/youtube?fields=id,name,likes
Only id, name and likes are returned

Now let’s call Google maps to get back the longitude and latitide geo location:
maps.googleapis.com/maps/api/geocode/json
Server is: maps.googleapis.com
Resources are: maps, api, geocode, json
JSON resource is added because GoogleMaps can return data in a number of different formats

Now let’s add parameters again:
maps.googleapis.com/maps/api/geocode/json?address=chicago&sensor=false
Here is the result:
GoogleMapsJson

Now let’s use this geo location to get pictures from instagram related to Chicago.
Go to: instagram.com/developer
In the menu on the left hand side, select API Console or type: instagram.com/developer/api-console
If we click on link “See it in full screen” we get to apigee:
https://apigee.com/console/instagram
Actually we can use the API dropdown to select from a bunch of public APIs.

Apigee

For now we use the media search api from instagram:
We can select the the request URL for the GET call via the dockable menu on the left hand side:
https://api.instagram.com/v1/media/source

instagrammediasearch

Now click query to enter the parameters. In this case longitude, latitude and distance (eg 20 metres).

instagramparameters
Click send and you will get a response:
Now if you look at the response, you will see a HTTP/1.1 200 OK
If you scroll down you see the body of the response.
Per Instagram picture there’s a URL you can copy to your browser to see the actual picture.

To find all APIs that are available, check out:
programmableweb.com/apis/directory

Finally. Instead of a GET request, you can also write data using a POST request. Normally with a POST you send dat
in the body of the request, something you can’t do in a browser. Download the Postman REST client.

Using Postman, you can add a body, but also one or more headers, like the OAuth or OAuth2 authorization header. OAuth is basically a username/password combination translated to an access token.
As an example let’s send an tweet out over the Twitter API:
https://api.twitter.com/1.1/statuses/update.json

PostmanTwitter
After clicking Send, you can go to your Twitter page and see the post.

One thought on “Playing around with REST APIs

Leave a Reply

Your email address will not be published. Required fields are marked *