Hope you are aware on basics of RESTful webservices in php..if not pls clickhere
Lets start up with a basic example on RESTful services. I would like to thank YRRHELP in youtube for providing best example on this..
First let me explain a basic difference between website and webservices. I too have the same doubt before i review YRR tutorial..he explained in detail..let me start with that..
Difference between Website & Webservices:
Website will be requested by humans and response will show in HTML
Webservices: In most of the cases, request will be done by programs and response will be generated in XML or Json
This webservices is widely used to communicate between heterogeneous system and platform like PHP,Windows and anyother platforms can communicate to java/android.
Lets start up with a basic example like, if you call up for a book(C/Java) in an URL should display its price in JSON format.
From the above pic you can notice that if i type “”C” it should display its price..similarly if i type “java” it should display java book price..
Here everything is coded in program and if you type some parameter it will display that desired result. This how webservices works..replace book name with city name and price with temperature will display the temperature of the city. This is the best real world example which i can explain.
Now lets peek into the code.. 😉
1. create a folder in wamp server with name rest
2. create a index.php file
3. create a functions.php file
4. create a htaccess file
Now just copy the code from below..then save and run 🙂
// process client request via URL
$price = get_price($name);
deliver_response(200,”book not found”,NULL);
header(“HTTP/1.1 $status $status_message”);
$json_response = json_encode($response);
$books = array(“java”=>299,”c”=>348,”php”=>267);
foreach($books as $book=>$price)
if($book == $find)
RewriteRule ^([a-zA-Z-]*)$ index.php?name=$1 [nc,qsa]
I hope by this time your brain is running with a doubt where comes this htaccess to live?? good question..let me explain with an image..
It will be very difficult to call up with parameters like below…
Hence by using htaccess we can do like below..
clickhere to know more about htaccess