Other web services?

I plan to create a calm web service (PHP).

api/user
api/user/[id]
api/ad
api/ad/[id];
etc

are the actual php files "user" and "ad"? and if not, how can I say (in my php file) which caller calls "user" or "ad"? any good tutorial on how to create a calm web service? Most guides cover the basics of leisure web services.

+3
source share
3 answers

, script (, index.php) , (, , PHP). script. script $_SERVER['PATH_INFO'] .

, script :

<?php
    phpinfo();
?>

script -, , . " PHP", PATH_INFO.

. http://php.net/manual/en/reserved.variables.server.php

EDIT2:
, HTTP GET POST , PHP $_GET $_POST, , . $_PUT/$_DELETE . POST , , PUT, DELETE, HEAD OPTIONS (, _method=PUT).

, GET POST, $_SERVER['REQUEST_METHOD'] , "" php://input (, file_get_contents('php://input')).

EDIT:
tdammers, Apache RewriteRules , URL- , , script, ( script, ):

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/api/index\.php(/|$)
RewriteRule ^/api/(.*)$ /api/index.php/$1 [QSA,L]
+5

Apache . , /api /api/index.php, URL (, /ad/user) . , http://example.com/api/ad/user - http://example.com/api/index.php?path=ad/user. index.PHP $_GET['path'] .

+1

, CakePHP, , .

0

Source: https://habr.com/ru/post/1766572/


All Articles