What Is a RESTful API?

Posted by Ely Hechtel in Uncategorized

What is an API?

API stands for Application Programming Interface and it basically allows a piece of software to talk to another. There are a lot of different APIs but lately, whenever you hear people talk about APIs (Google API, Twitter API etc.) they are talking about RESTful API.

What is a RESTful API?

REST stands for REpresentational State Transfer. This essentially refers to a style of web architecture that has many underlying characteristics and governs the behavior of clients and servers. REST is defined by 6 constraints: client-server, stateless. Cacheable, Layered system, Uniform Interface, Code on Demand (optional).

This kind of API works pretty much as any website – you send your request to a server via HTTP and you will get a website in response.

A REST API defines a set of functions which developers can perform requests and receive responses via HTTP protocol such as GET, DELETE and POST.

If an API follows the follows REST “rules”, it can be called RESTful API. Thanks to this interface, resources can be called upon singularly.

Down to earth example

We all know what a facebook page looks like:

facebook youtbe page

What if we change the “www” in the URL Bar to the facebook API using “graph”?
You will get some code that might be nonsense, but that is actually structured data, like an excel spreadsheet would be, with the difference that it could be XML or JSON.
In Excel, you can ask what the key value in Cell A6 is and look at it.

With RESTful every resource has a key value, called e.g. JSON array, and you can ask for key values singularly. In the case of a facebook page, you could ask for the data under the key “likes” to find out how many likes a page has.

Here is another example with google maps:
So we are asking for:
Server = maps.googleapis.com
Resource =

/maps
/api
/geocode
/json

Request = ?address=Chicago

So our whole URL would look like this:
http://maps.googleapis.com/maps/api/geocode/json?address=Chicago

We will get the following information back:

{
"results" : [
{
"address_components" : [
{
"long_name" : "Chicago",
"short_name" : "Chicago",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Cook County",
"short_name" : "Cook County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Illinois",
"short_name" : "IL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "USA",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Chicago, Illinois, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 42.023131,
"lng" : -87.52366099999999
},
"southwest" : {
"lat" : 41.6443349,
"lng" : -87.9402669
}
},
"location" : {
"lat" : 41.8781136,
"lng" : -87.6297982
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 42.023131,
"lng" : -87.52404399999999
},
"southwest" : {
"lat" : 41.6443349,
"lng" : -87.9402669
}
}
},
"place_id" : "ChIJ7cv00DwsDogRAMDACa2m4K8",
"types" : [ "locality", "political" ]
}
],
"status" : "OK"
}

Under the key array “location” we can see the longitude and latitude of Chicago.

When you send one of these requests, you don’t know which server you are contacting or if the server is online at the moment. You may get cached information.

Using this method, you can ask for any public information (resource) there is that uses HTTP protocol.

If you want to POST, EDIT or DELETE resources, you will probably have to be logged into your account. And how can you login through an API?

You would need and API Authentication Key, that substitutes your login details. Once you set this, you can also post, edit and delete resources on your own account.

Discuss: What Is a RESTful API?
0 Comments

Free Trial

Get access to a free 14-day trial version, or contact Sales for more information.