php API daemon process over a url
I need a background process to be an API over a URL.
For example, the url http://www.msite.com/myapi.php will read incoming protocol and reply.
What is the best way to accomplish this scenario?
Should I just treat this as a regular web page?
What are the pros/cons for using a we开发者_开发知识库b page url as an API?
You should implement this as REST service. Check this URL out.
You need to create a proper controller (in case you use MVC approach) and implement proper methods corresponding to your API (HTTP request methods are very important topic here).
Just to illustrate, I allowed myself to paste code from URL I embedded here:
GET request to /api/users – List all users
GET request to /api/users/1 – List info for user with ID of 1
POST request to /api/users – Create a new user
PUT request to /api/users/1 – Update user with ID of 1
DELETE request to /api/users/1 – Delete user with ID of 1
Just to notice, you can also use different approach like XML-RPC or SOAP.
精彩评论