diff --git a/src/Http/Request.php b/src/Http/Request.php index 6a495e06..b34b30c4 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -266,6 +266,20 @@ public function getRawBody(): ?string } + /** + * Returns decoded content of HTTP request body. + */ + public function getDecodedBody(): mixed + { + $type = $this->getHeader('Content-Type'); + return match ($type) { + 'application/json' => json_decode($this->getRawBody()), + 'application/x-www-form-urlencoded' => $_POST, + default => throw new \Exception("Unsupported content type: $type"), + }; + } + + /** * Returns basic HTTP authentication credentials. * @return array{string, string}|null