Hardware Reference
In-Depth Information
Take out the foreach()
block from the previous
example and replace it as shown here.
New lines are shown in blue.
Modify It
<?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 />";
}
Type the URL as follows into your
browser (change the hostname and
path as needed):
http:// www.example.com /
myService/runnerName/31/1/2012/
distance/12.45/time/0:45:34
$position = array_search('time', $parameters);
if ($position) {
$time = $parameters[$position+1];
echo "Your time: ".$time."<br />";
}
?>
When you type this into the browser,
you'll get back:
Your distance: 12.45
Your time: 0:45:34
When you combine this approach with standard
HTML forms using HTTP POST, you have two
ways of passing in parameters, and your URLs
reflect the state of the resource. It makes for a powerful
and flexible way to build the architecture of a web service,
resulting in URLs that are both machine-readable and
easier for humans to understand.
Every server-side programming language has a variety of
frameworks designed to make REST easier to implement.
PHP frameworks like Cake and CodeIgniter, Ruby frame-
works like Rails and Sinatra, and many others attempt
to make it easier for you to build applications, and their
application programming interfaces (APIs) are designed to
encourage you to build in a RESTful way. With these, you
can often build proxy applications that take data in a more
complex format, and summarize it in a simpler format for
the more limited devices in your system.
X
 
Search WWH ::




Custom Search