Hello everyone! I’m trying to handle the HTTP request HEAD using SLIM and it doesn’t seems to work like other methods. I can’t have $app->head like I would with GET, POST, PUT or DELETE.
What is the the (best) way to achieve this?
Thanks!
Hello everyone! I’m trying to handle the HTTP request HEAD using SLIM and it doesn’t seems to work like other methods. I can’t have $app->head like I would with GET, POST, PUT or DELETE.
What is the the (best) way to achieve this?
Thanks!
There is indeed no App::head
method.
You can use App::map
to create a route for requests using the HEAD method:
$app->map(['HEAD'], '/test-head', function(Request $request, Response $response) {
return $response->withHeader('X-Test', 'head');
});
Using App::any
will actually not work, as it will only match the methods GET, POST, PUT, PATCH, DELETE and OPTIONS.
It worked! Thanks a lot!