Skip to content

Commit

Permalink
Add support for raw JSON POST / PUT body
Browse files Browse the repository at this point in the history
  • Loading branch information
cdgco committed Apr 27, 2023
1 parent 9fa2c60 commit c0c81df
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions RestService/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -1673,19 +1673,30 @@ public function run() {
foreach ($params as $param) {
$name = $this->argumentName($param->getName());

// If argument is _ (underscore), pass all arguments
if ($name == '_') {
$thisArgs = array();
foreach ($_GET as $k => $v) {
if (substr($k, 0, 1) == '_' && $k != '_suppress_status_code')
$thisArgs[$k] = $v;
}
$arguments[] = $thisArgs;
} else {
}
// Else, pass the named argument
else {

// Get PUT data (also supports JSON encoded POST data)
$_PUT = null;

if (isset($_SERVER['REQUEST_METHOD'])) {
$method = $_SERVER['REQUEST_METHOD'];
if ('PUT' === $method) {
parse_str(file_get_contents('php://input'), $_PUT);
if ('PUT' === $method || 'POST' === $method) {
try {
$_PUT = json_decode(file_get_contents("php://input"), true, 512, JSON_THROW_ON_ERROR);
}
catch (\JsonException $exception) {
parse_str(file_get_contents('php://input'), $_PUT);
}
}
}

Expand Down

0 comments on commit c0c81df

Please sign in to comment.