Story #63642: Introduce Request/Response model for frontend rendering
Use Request Response model in JsonView
Updated by Alexander Schnitzler 12 months ago
Making JsonView use Request/Response is not that easily possible without changing the ViewInterface in general since method render() must return a string. Still, this bug report is totally valid and must be addressed. My idea is as follows:
Make every action return a ResponseInterface and make the user do something like this:
$response = new Response($this->view->render()); $response->setHeader('Content-Type', 'application/json');
Unfortunately we need people to set headers manually outside the JsonView or we let them use the core JsonResponse which does the job for them. But setting headers in the view is a no go indeed.