In many cases we say that using REST API we get the response. What does this REST API Really Means ?! This is Going to be a tutorial about the REST API and also what all things that has to be considered when designing a RESTful API.I like to keep myself short and simple so lets jump in to our topic directly.
WHAT IS RESTful API ALL ABOUT?
The term Rest API is coined by Roy Fielding - LINK. Representational State Transfer is a architectural style for communication with different distributed hypermedia systems. Defenition dont sounds Good right? Lets take an example to make it clear. You have a data base that contains the information about users of your website.Now you are planning to develop a Ios and Android app for your website.That make use of the same data in the web server database. At that time you need to make a Restfull API to give the reponse object either in xml or json formats.
To understand about RESTful API first we need to understand how the HTTP protocol works.It works basically by request and response modal. The request can be either a GET or POST. GET caches the data at the client side and POST doest caches the data.HTTP verbs are used to specify what action to be done in the specified URL(Locates a resource in server).
Where the POST is action specifying what action to be done. Similarly there are other http verbs like GET,PUT,DELETE.
Eg for a REST API
The above URL can be made to request the detail of user “xxx”. So that we get the data in json or xml format. This could be easily done in using php.
user?id=”xxx” in the url is same as the user/xxx. Where the .htaccess file is used to rewrite url. So it easy to get the name of the user and giving a json response in php.
DOES A URL GIVING A JSON RESPONSE IS ALONE CONSIDERED TO BE A REST API?
Defenetly not.A RESTful API is still more than it.Many say that their application has a REST api. Even you might have one. Lets check weather it is using REST api.To say a application uses a REST API , it must consider 6 constraints.If it satisfys all of it, then it is said to be REST api
WHAT ARE ALL THE CONSTRAINTS?
- Uniform Interface
- Client Server
- Layered System
- Code On Demand