Reputation: 249
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. 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. Node JS example:
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. 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.
Upvotes: 0
Views: 279
Reputation: 1439
You can fetch the request method in PHP using $_SERVER['REQUEST_METHOD']
. 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. These come to mind:
Upvotes: 1