Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Headers to response #1888

Open
nicraMarcin opened this issue Apr 25, 2018 · 1 comment
Open

Add Headers to response #1888

nicraMarcin opened this issue Apr 25, 2018 · 1 comment

Comments

@nicraMarcin
Copy link

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?

@thibaut-algrin
Copy link

Hello,

You can create a view_handler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants