private function buildResponse(Event $event)
    {
        $request = $event->getData()['request'];
        $response = $event->getData()['response'];

        if ('xml' === Configure::read('ApiRequest.responseType')) {
            $response->withType('xml');
        } else {
            $response->withType('json');
        }

        $response->cors($request)
                ->allowOrigin(Configure::read('ApiRequest.cors.origin'))
                ->allowMethods(Configure::read('ApiRequest.cors.allowedMethods'))
                ->allowHeaders(Configure::read('ApiRequest.cors.allowedHeaders'))
                ->allowCredentials()
                ->maxAge(Configure::read('ApiRequest.cors.maxAge'))
                ->build();

        return true;
    }