Playing with RestAPI is fun!!
For the past few weeks, I have had the opportunity to play with REST API's. You might be thinking, that API's are too complicated to understand. Well I used to think that before I started with it. If you deal with Web apps all day long or somehow you are associated with web technologies, REST will not be difficult for you to understand. Be aware, you must understand the basics of HTTP, thing like how it works, what it isn't etc. Just to check Ask yourself do I know HTTP Verbs ? Do I know the HTTP Status Code ? If someone tells you "HTTP is stateless" do I know what that means ? If you were able to answers all those questions without using Google , then you are in the right place to get started with RestFul . If you don't know what these means just "Google it" and you will be an expert in few reads.
REST Stands for Representational State Transfer. (Yes I did Google for it, If you know me, you will know that I don't care what it stands for but more concerned about what it does)
Now if you have already played with other forms of webservices like SOAP, REST will be a different experience. SOAP usually has XML based method invocation. That means once you have opened a HTTP connection you pre-generate your XML (Soap-Envelope) and POST it, now based on the input received from the XML the Web Service will either retrieve or manipulate server data.
However REST based Web Services are "Action Based". You don't execute a method directly. You perform one of the HTTP Verb Action. So the HTTP Verbs like GET , POST , PUT , DELETE is now your standard methods. Where you are invoking it determines what will be the effect of that action. Also the data is send and received is as JSON not XML.
Very Simple Example : Let say I have a REST based API which allows you to view all the movies I have. All you need to do is issue a GET request to my API URL ;
GET /AviksAPI/v2.0/movies
It will return all the list of movies in a JSON format to your client or browser. Simple Huh!
What if you want to add some data to ? Then you no longer GET them but POST . Here is what you do;
POST /AviksAPI/v2.0/movies
Data :
movie=Batman
Pretty nifty right! Few things to remember, in the above example "movies" is know as RESOURCE in the world of REST. Also as REST is based on the HTTP verbs it provides HTTP status code as return code.
Well generally you won't be able to access an REST API directly, you will need some form of authentication..But that is topic for some other time. For now enjoy your life and REST harder :).
Great post Avi. RESTful API development now the trend in DevOps era. By having an API, the the provider service / core application has the potential to become a new business platform from which other services grow. If people can find it easy to consume then your platform makes more money :). Facebook, Twitter, Google, GitHub, Amazon, Netflix and even now Banks have open their doors so that more and more customers consume their data and they become BIG... @Avik, Good Start. Do you also have plan to suggest how a normal business can create API in few minutes and manage/ secure?
keep on posting :)