But what if there is a PUT, PATCH, or any type of request other than POST?
Well, as you develop the API , if you choose , whether it takes only POST, PUT, POST+ PUTor any other combination of request headers.
An API should not be designed to “accept and process” everything that a third-party application sends to your API. This is an application (I mean an application that connects to the API) to prepare the request in such a way that the API accepts it.
, ( , -) (, , ..).
, , API, , -, .
- @Adil Abbasi, , ( php://input). , php://input enctype = "multipart/form-data" .
<?php
$input = file_get_contents('php://input');
$requestParams = json_decode($input, true);
if ($requestParams === FALSE) {
header("HTTP/1.1 400 Bad Request");
die("Bad Request");
}
enctype = "multipart/form-data" - STDIN - docs :
<?php
$bytesToRead = 4096000;
$input = fread(STDIN, $bytesToRead );
if ($input === FALSE) {
}
$requestParams = json_decode($input , true);
if ($requestParams === FALSE) {
header("HTTP/1.1 400 Bad Request");
die("Bad Request");
}