tempest-framework icon indicating copy to clipboard operation
tempest-framework copied to clipboard

[Bug]: Support json bodies in requests

Open NeoIsRecursive opened this issue 1 year ago • 1 comments

Description

When trying to send a json payload to a tempest controller, the requests body isn't set to an array (I believe this is how the laminas-diactoros package works, or atleast according to https://stackoverflow.com/a/73671455), which causes errors when doing validation or accessing the properties on a "custom" reqeust.

When I added something like this in the router dispatch method it seems to work, but I guess its not the best solution:

/** @var PsrRequest $request */
if ($request->getHeader('content-type')[0] === 'application/json') {
    $request = $request->withParsedBody(json_decode($request->getBody()->getContents()));
}

Benefits

Well, the ability to build json apis

NeoIsRecursive avatar Oct 01 '24 08:10 NeoIsRecursive

Yeah this should definitely work. I'll look into it!

brendt avatar Oct 01 '24 08:10 brendt

Fix will be included in alpha.6

brendt avatar Mar 06 '25 12:03 brendt