Define: Rest
Representational state transfer (REST) is a style of software architecture for distributed hypermedia systems such as the World Wide Web. It is not strictly a method for building what are sometimes called “web services.”
The terms “representational state transfer” and “REST” were introduced in 2000 in the doctoral dissertation of Roy Fielding, a principal authors of the Hypertext Transfer Protocol (HTTP) specification. The terms have since come into widespread use in the networking community.
REST strictly refers to a collection of network architecture principles which outline how resources are defined and addressed.
The term is often used in a looser sense to describe any simple interface which transmits domain-specific data over HTTP without an additional messaging layer such as SOAP or session tracking via HTTP cookies. These two meanings can conflict as well as overlap.
Systems such as PHP5 which follow Fielding’s REST principles are often referred to as “RESTful”. Systems that USE REST Feeds are reffered to RESTafarians.
Rest in PHP
REST, is a Web service architectural style in which the focus is on the presence of resources in the system.Each resource must be identified by a global identifier—a URI. To access these resources, clients communicate with the REST service by HTTP, and the server responds with a representation of the resource. This representation is often in the form of HTML or XML.
In simple words, Rest is a way of sending a query to a server. This query can include informatiom such as API Key, User name and Password for secure identification, or a query term such as search=$term to search the website for $terms. The results are returned in either HTML or more prefered XML.
REST needs API
All REST services need an API to allow developers to code the use of a RESTafarian website. This is because REST does not provide a WSDL or hany any common interface for communication.
Working with REST
Most REST requests are responded with XML data this means PHP can use SimpleXML or DOM. In this example we will be using SimpleXML because its more simpler to explain.
In this example we will use delicious.com, which is a bookmark website where you and others bookmark websites with tags to find them later. We can query delicious and ask them for all bookmarks related to the word Zend. Delicious will then respond to us all the websites it has been tagged with Zend:
$u = ’username’;
$p = ’password’;
$query = 'ZEND';
$fooTag = "https://{$u}:{$p}@api.del.icio.us/v1/posts/all?tag={$query}";
$bookmarks = new SimpleXMLElement($fooTag, NULL, true);
foreach ($bookmarks->post as $bookmark){
echo ’<a href="’ . htmlentities($bookmark[’href’]) . ’">’;
echo htmlentities($bookmark[’description’]);
echo "</a><br />\n";
}
$footag s the resource identifier, for the data to be retrieved.
SimpleXML handles the request and the data received, then we use the SimpleXML object and foreach to output the matching bookmarks.