Permalink
Browse files

Added REST examples from Chapter 11

  • Loading branch information...
Tom Igoe
Tom Igoe committed Oct 4, 2011
1 parent 2405ebe commit 4cae0f1585bb39ca45f662e0b57b1e39fd7bfe74
@@ -0,0 +1,8 @@
RewriteEngine On
# put in the base path to your directory:
RewriteBase /mtt2/myservice
# redirect anything after the base directory to index.php:
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
@@ -0,0 +1,16 @@
<?php
/*
RESTful reader
Context: PHP
*/
// split the URI string into tokens:
$tokens = explode("/", $_SERVER['REQUEST_URI']);
foreach($tokens as $item) {
echo "Item: ";
echo $item."<br>";
}
?>
@@ -0,0 +1,23 @@
<?php
/*
RESTful reader 2
Context: PHP
*/
// split the URI string into a list:
$parameters = explode("/", $_SERVER['REQUEST_URI']);
$position = array_search('distance', $parameters);
if ($position) {
$distance = $parameters[$position+1];
echo "Your distance: ".$distance."<br />";
}
$position = array_search('time', $parameters);
if ($position) {
$time = $parameters[$position+1];
echo "Your time: ".$time."<br />";
}
?>

0 comments on commit 4cae0f1

Please sign in to comment.