diff --git a/src/Http/Request.php b/src/Http/Request.php index f0511b77..5c7ac021 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -267,6 +267,20 @@ public function getRawBody(): ?string } + /** + * Returns decoded content of HTTP request body. + */ + public function getBody(): 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