Can't access URL/Query params from PUT request

When attempting to parse the URL/Query string from a PUT request it is returning as empty array.

With an Expressive route like:

$app->put('/forms/{id:\d+}', Handler\FormsUpdateHandler::class, 'forms.update');

With a Content-Type of ‘application/Json’, containing a Json object in the Body, while making a PUT request to http://localhost/forms/2/

    public function handle(ServerRequestInterface $request) : ResponseInterface
        echo $request->getQueryParams()['id'];die();

I’ve added the helper to allow getParseBody(), but haven’t found anything allowing to parse the URL.

Does anyone have any insight into how to get the URL args in a PUT request with Expressive?

Hmm, id is not a query parameter here, but rather an attribute defined by routing.

A query parameter would be ?id=123

1 Like
$app->put('/forms/{id:\d+}', Handler\FormsUpdateHandler::class, 'forms.update');

$request->getAttribute('id'); // = 1
$request->getQueryParams()['id']; // = 2
$request->getParsedBody(); // Returns array with posted (form) values

Doh! You’re right. It’s been a long day. :stuck_out_tongue: