[英]Identification of incoming http requests in PHP
Have a little problem. 有一点问题。 I have some task, where must process some data in client server system. 我有一些任务,必须在客户端服务器系统中处理一些数据。 On client side i can create diferent http request on JS. 在客户端,我可以在JS上创建不同的http请求。 For example: 例如:
$http.post(url, DataObj);
$http.get(url, DataObj);
$http.insert(url, DataObj);
$http.deletet(url, DataObj);
$http.update(url, DataObj);
On the server side on NodeJS I can identify type of request, get request data and do some server logic, after that i can send back some ansver or data object. 在NodeJS的服务器端,我可以识别请求的类型,获取请求数据并执行一些服务器逻辑,然后再发送回ansver或数据对象。 Node JS example: Node JS示例:
var apiRoutes = express.Router();
apiRoutes.post('route', function(req, res) {
someFunction(req.params.data);
res.send(ResponseDataObj); }
or
apiRoutes.delete('route', function(req, res) { .... }
The problem is that I can not understand how client-side PHP must identify the type of request (post, update, actually), get request data to process it and send the result result data. 问题是我无法理解客户端PHP如何识别请求的类型(发布,更新,实际),获取请求数据以对其进行处理并发送结果结果数据。 Can I do all these manipulations in a single script, or must to make a few scripts for each operation with data like a : 我可以在单个脚本中进行所有这些操作,还是必须为每个操作制作一些脚本,例如:
getData.php
insertData.php
updateData.php
deleteData.php
If anyone have a similar task please share code examples that I could understand, or reference to examples. 如果有人有类似的任务,请分享我能理解的代码示例,或引用示例。 Thank you very much. 非常感谢你。
You can fetch the request method in PHP using $_SERVER['REQUEST_METHOD']
. 您可以使用$_SERVER['REQUEST_METHOD']
在PHP中获取请求方法。 However for a more structured approach (as you're doing with Express
) I would advice using a lightweight framework to do the heavy lifting for you. 但是,对于更结构化的方法(就像使用Express
),我建议使用轻量级框架为您完成繁重的工作。 These come to mind: 这些想到:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.