I am planning to create a cool web service (PHP).
api / user api / user / [id] api / ad api / ad / [id]; Etc.
"User" and "Advertising" are actual PHP files? And if I can not tell (on my php file) that the caller is saying "user" or "ad"? Any good tutorial on how to create a terrific web service? Most of the tutorials cover the basics of the rest of the web services.
For good, simple services, you have a single script file (like named index.php
) as the entry point that transmits different routes for your actions (which is definitely in other PHP files) it is said to be one of the paths you have after the name of the script Was added In the script, you can use $ _ SERVER ['PATH_INFO']
to define that path.
You can experiment a little bit in this material by simply creating a script with this content:
& lt ;? Php phpinfo (); ? & Gt;
If you request this script in a browser from your web server, you will see all the relevant data printed in a good list. To see your PATH_INFO
, scroll down to PHP variable .
EDIT2: Additionally, access methods for HTTP received and POST Limiting your life makes it easy because in PHP $ _ GET
and $ _ POST
variable but not the example $ _ PUT
/ $ _ DELETE
and like, however, you can send POST requests with a specific variable, so that they PUT , DELETE , HEAD or options functions (like _method = PUT
).
Use $ _ SERVER ['REQUEST_METHOD']
to determine the received and POST , method And read the data sent with the request from the special "file" php: // input
(for example, file_get_contents ('php: // input')
).
Edit:
As stated, Apache rewrite rules are useful to make your URL beautiful, in this case to hide the name of the script like this (Definitely depends on your script's location):
RewriteCond% {REQUEST_URI} at RewriteEngine! ^ / Api / index \ .php (/ | $) revised rule ^ / api /(.*)$ /api/index.php/$1 [QSA, L]
Comments
Post a Comment