[Symfony] Restrict a route to the POST method via annotations

Published on 2018-09-26 • Modified on 2018-09-26

Sometimes you must restrict an action to be accessible with a given method only. That is the case for example for the "check_path" route used by the Symfony security component that mustn't be available with GET but only with the POST method.
If you don't restrict the route to the POST method and if you try to access the route via get with your browser you get a 500 error. Otherwise you have a HTTP_METHOD_NOT_ALLOWED error (code 405) which isn't a critical error and doesn't have to be handled by your application.


/**
 * @Route("/login_check", name="user_security_check", methods={"POST"})
 */
public function checkAction(): void
{
}

 More on Stackoverflow  Random snippet

  Work with me!


Call to action

Did you like this post? You can help me back in several ways: (use the "reply" link on the right to comment or to contact me )

Thank you for reading! And see you soon on Strangebuzz! 😉

COil