Hello
I was implementing a route like this:
$app->group('/pattern', function () {
$this->get('', '\MyClass:getMethodOnController');
$this->head('', '\MyClass:headMethodOnController');
});
And Slim just crashes because apparently it doesn't support HEAD for routing patterns. Why? Is this an oversight or is there a good reason for it? I find it odd because the $request object has the HEAD method available like $request->isHead();
I was encouraged to open an issue on Slack.
It is supported, there just is no shortcut method for it.
$this->map(['HEAD'], $pattern, $callable);
Ah, okay. Perhaps this would be a good reason to add one then. If not for anything then just to avoid other similar questions.
Just a thought, perhaps a time to drop the convinience methods ->get, ->post ->put at the next appropriate major version (4.x or whatever).
The idea being that map is about the same number of characters and is much more flexible. Jut an alternative idea
I don't agree. I think we should add the missing shortcuts instead. Since they're mapped to the defined HTTP protocol verbs I don't see any reason to not have them. They are very convenient and make the code easily readable in my opinion.
BTW what is the reason ->head(...) shortcut is not implemented?
I would guess that it was missed.
@nickdnk What's your use case for needing a separate HEAD method?
The same as when needing any other route method I guess. I just think it's weird that we have shortcuts for some http verbs but not for others. It's inconsistent in my opinion. I suppose the argument against it is that an endpoint supporting HEAD should also support some other method, and hence use map. But if you group methods into something and allow POST, GET and HEAD on the root within that group, you will need the HEAD shortcut or use map with only 1 method.
Sent from my iPhone
On 18 Nov 2016, at 09.19, Rob Allen <[email protected]notifications@github.com> wrote:
@nickdnkhttps://github.com/nickdnk What's your use case for needing a separate HEAD method?
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/slimphp/Slim/issues/2033#issuecomment-261473996, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AIBYshwGvwVh8DWbBv4re3Pici2fe13Xks5q_V-RgaJpZM4KtBwK.
The thing is: HEAD is _exactly the same_ as GET, except that the body is omitted. Slim already supports that.
So writing an $app->head() would imply a special use-case.
Aha, okay. I thought the logic in a HEAD request might differ from that of a GET as in "use head to check for something on and endpoint but return no body". I didn't know they were supposed to be identical. In that case I guess it's not an oversight.
No ask no learn :)
Sent from my iPhone
On 18 Nov 2016, at 11.42, Rob Allen <[email protected]notifications@github.com> wrote:
The thing is: HEAD is exactly the same as GET, except that the body is omitted. Slim already supports that.
So writing an $app->head() would imply a special use-case.
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/slimphp/Slim/issues/2033#issuecomment-261501931, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AIBYsknWHvYZx65e9IASgMnCU-SYh7oLks5q_YENgaJpZM4KtBwK.
@akrabat @codeguy We routinely use HEAD routes to trigger a poll of an external resource without returning the result. We then have a corresponding GET route to trigger the poll and return the result.
I believe this falls within the guidelines of the HTTP protocol. It would be helpful if Slim included the $app->head() convenience method.