what are the Stateless Routes? #50129
-
as the documentation is said its makes the response got cached but only when the session starts during the request and as i know session can start only when we logged in as an example so the session will start and user can access his pages and his data |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Stateless routes should not use the session, as that will make the response not cacheable. If a route is marked stateless and the controller uses a session, symfony will throw an exception (in dev mode) or log a message (in prod mode). |
Beta Was this translation helpful? Give feedback.
-
Indeed stateless refers that a route does not require any server-side state to be maintained between requests class Controller extends AbstractController
{
/**
* @ route("/stateless", name="stateless_route", stateless=true)
*/
public function stateless(): Response
{
// Attempt to use the session
$session = $this->get('session');
$session->set('token', '123');
// Return a response
return new Response('dummy response');
}
}```
using $this->get('session') or any session methods are not allowed in this stateless route |
Beta Was this translation helpful? Give feedback.
Indeed stateless refers that a route does not require any server-side state to be maintained between requests
here is code that will show error when using the server is this