I need some better understanding on how to implement REST services with php
From what I have read sofar, they say "use logical adresses" and preferably don't use get variables at all.
What I don't see is how these url's are getting processed. Like www.somename.com/product and product is supposed to be not a physical address.
I mean, you do need some entry file that has the php processingcode that does the real work, don't I?
How does this work?
After that I can echo the data back between custom xml tags and the client app can parse this.That part I still remember from dealing with ajax. Only with REST you put all the resources(data or pieces off data) within a url.
So that takes me back to my original question. How are these logical url's being proccessed?? (within php that is)
Thanks, Richard
The basic answer is something that someone mentioned in the above comments: mod_rewrite. By configuring Apache to use mod_rewrite to route your web requests, you can have all resource requests go through a single entry point. Example:
RewriteEngine On
RewriteRule !\.(js|ico|gif|jpg|png|css|html|swf|mp3|wav)$ index.php [L]
That sends all requests for a non-static resource to index.php. index.php can then make a decision on what content to load, say by examining $_SERVER['SCRIPT_URI'] and parsing out the fact that the request might have been /animals/cat.
Many MVC frameworks embrace this concept and utilize this routing method as a way to load the controllers and views.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With