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

Get response function with relation in query string #109

Open
AlessandroMinoccheri opened this issue Jan 29, 2018 · 2 comments
Open

Get response function with relation in query string #109

AlessandroMinoccheri opened this issue Jan 29, 2018 · 2 comments
Assignees

Comments

@AlessandroMinoccheri
Copy link
Contributor

AlessandroMinoccheri commented Jan 29, 2018

Q A
Bug report? no
Feature request? yes
QueryBundle version 2.4

We can add the possibility to return a serialized and standard response with Its relations passed into query string.
Something like getResponse() because when you create a new project you need to copy always the same function to get your correct serialized, standard response.
I mean this code:

protected function createApiResponse($data, $statusCode = 200, $groups = [])
    {
        $requestStack = $this->get('request_stack');
        $serializer = $this->get('jms_serializer');

        $groups = array_merge(['Default'], $groups);
        $groups = array_merge($groups, explode(',', $requestStack->getCurrentRequest()->query->get('rel', 'Default')));
        $groups = array_unique($groups);

        $json = $serializer->serialize(
            $data,
            'json',
            SerializationContext::create()
                ->enableMaxDepthChecks()
                ->setGroups($groups)
        );

        return new Response($json, $statusCode, array(
            'Content-Type' => 'application/json',
        ));
    }

What do you think?

@sensorario
Copy link
Contributor

sensorario commented Feb 7, 2018

We could create a new service/component that aims to build responses. Serializer and RequestStack will be injected. Will this become the QueryBundle's custom responder (CustomResponder)?

@AlessandroMinoccheri
Copy link
Contributor Author

I think that it could be very useful

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

No branches or pull requests

2 participants