FOSRestBundle
FOSRestBundle copied to clipboard
Add Headers to response
Hello How to add custom headers to response?
config:
fos_rest:
body_listener: true
format_listener:
rules:
- { path: '^/api', priorities: ['json'], fallback_format: json, prefer_extension: false }
- { path: '^/user', priorities: ['text/html'], fallback_format: 'text/html', prefer_extension: false }
param_fetcher_listener: true
view:
view_response_listener: 'force'
formats:
json: true
I have in controller
/**
* @Rest\Get("/", name="index",)
* @param UserRepository $userRepository
* @return array
*/
public function index(UserRepository $userRepository): array
{
$users = $userRepository->findAll();
return $users;
}
Now I need to add custome header X-Total-Count
as count($users). How to do it with FOSRestBundle?
Hello,
You can create a view_handler