Hi I’m trying to build the server side of an application using REST archtecture with PHP. later I will make a client for android to consume those services.
I already know what is a RESTful application.
but still got something confuse:
if I want to get retrieve information of a user, the url I should access is http://www.domain.com/user/123 according to REST. but that means for every user in DB I should make a .php?? that sounds illogical. or there are something like java which use logical url, or just rewrite the url to something like http://www.domain.com/getusr.php?id=123 ??
fixed: is url rewrite the correct way to interpret request url from clients for a webservice in php?
for example: if someone request http://www.domain.com/user/123, I should rewrite to http://www.domain.com/getusr.php?id=123
or maybe php is not for webservice?
thanks
You need to rewrite the url to
www.domain.com/getusr.php?id=123, that way you need only 1 php file , all requests in form ofwww.domain.com/user/123would go to a single getusr.php file . You can achive this using apache mod_rewrite ( there are tons of examples around so i whont post another one ) .Edit
Check this link , that contains a few good examples .
Or you can use this code bellow ( place it inside a “.htaccess” file at the root of you’re web directory , where getusr.php should be placed allso )