@param ApiResponse $apiResponse to convert to a Symfony Response.
@param Request $request that needs this Response.

@return Response
161374
public function toSymfonyResponse(ApiResponse $apiResponse, Request $request)
    {
        $format = $request->getRequestFormat($this->defaultResponseFormat);
        $serialized = $this->serializer->serialize($apiResponse->getData(), $format);
        $response = new Response($serialized, $apiResponse->getStatusCode(), $apiResponse->getHeaders());

        $response->headers->set('Content-Type', $request->getMimeType($format));

        return $response;
    }
858248
protected function processApiClientException(
        ApiClientException $exception,
        RequestInterface $request
    ): ResponseInterface {
        if (!$exception instanceof UnauthorizedException) {
            throw $exception;
        }

        $this->clearAuthorizationToken();
        $promise = $this->createPromiseForRequest($request, false);
        return $promise->wait();
    }
461891
public function postRequest( Request $request ) {
		$response = $this->getClient()->request(
			'POST',
			$this->apiUrl,
			$this->getClientRequestOptions( $request, $this->getPostRequestEncoding( $request ) )
		);

		return $this->decodeResponse( $response );
	}
1145697
public function send(Request $request): Response
    {
        $this->serialInterface->send($request->encode());
        return $this->receiveResponse($request->getTimeout());
    }
508968
public function execute(RequestInterface $request): ResponseInterface
    {
        $this->supports($request);

        if ($request instanceof InputInterface) {
            $request->validate();
        }

        $client = $this->getClient();

        $data = array_replace($request->toArray(), [
            'carrier' => $client->getCarrier(),
            'key'     => $client->getKey(),
        ]);

        $response = $client->call($this->getMethodName(), $data);

        return $this->parseResponse($response->getBody()->getContents());
    }
1152092
public function apiAction(Request $request)
    {
        if ($request->isXmlHttpRequest() or $request->headers->get('Content-Type') =='application/json') {
            $pathInfo = $request->getPathInfo();
            if(!$this->getApiRequestAllow()->isAllow($pathInfo)){
                throw new NotFoundHttpException('No route allow for " '.$request->getMethod().' '.$pathInfo.'"');
            }
            $query_string = null;
            if ($request->server->get('QUERY_STRING')){
                $query_string = '?' .$request->server->get('QUERY_STRING');
            }

            $url_api = $pathInfo . $query_string;

            /*
             * Only is configurable the first folder
             * internalapi/users/username-available
             * is changed to api/users/username-available
             */
            $array = explode("/", $url_api);
            unset($array[1]);
            $text = implode("/", $array);

            $url_api = "/api".$text;

            $apiUri = trim($url_api,'/');
            try{
                return $this->container->get('antwebes_chateaclient_bundle.http.api_client')->sendRequest('GET',$apiUri);
            }catch (ClientErrorResponseException $e){
                $headersGuzzle = $e->getResponse()->getHeaders()->toArray();
                $headersSymfony = array();
                foreach($headersGuzzle as $key=>$value){
//this header is not suporter in symfony
                    if($key != 'Transfer-Encoding' && $value !== 'chunked'){
                        $headersSymfony[$key] = $value[0];
                    }
                }
                return new Response($e->getResponse()->getBody(true),
                    $e->getResponse()->getStatusCode(),
                    $headersSymfony
                );
            }
        }else{
            throw new NotFoundHttpException();
        }
    }
1346630
public function transform(ApiRequest $request, ApiResponse $response, array $context = []): ApiResponse
	{
		// Return immediately if context hasn't defined renderer
		if (!isset($context['renderer'])) return $response;

		// Fetch service
		$service = $this->container->getByType($context['renderer'], false);

		if (!$service) {
			throw new InvalidStateException(sprintf('Renderer "%s" is not registered in container', $context['renderer']));
		}

		if (!is_callable($service)) {
			throw new InvalidStateException(sprintf('Renderer "%s" must implement __invoke() method', $context['renderer']));
		}

		return $service($request, $response, $context);
	}
731700
public function send(Request $request)
    {
        $response     = new IndexQueryResponse();
        $httpRequest  = $this->createHttpRequest($request);
        $httpResponse = $this->client->send($httpRequest);
        $code         = $httpResponse->getStatusCode();

        if ( ! isset($this->validResponseCodes[$code])) {
            throw RiakTransportException::unexpectedStatusCode($code);
        }

        $multipartIterator  = new MultipartResponseIterator($httpResponse);
        $responseIterator   = new HttpIndexQueryResponseIterator($request, $multipartIterator);
        $response->iterator = $responseIterator;

        return $response;
    }
157286
public function api(Request $request)
	{
		$reflectClassRequest = new \ReflectionClass($request);
		$className           = $reflectClassRequest->getShortName();
		$className           = str_replace('Request', 'Api', $className);
		$namespace           = str_replace('\Request', '\Api\\', $reflectClassRequest->getNamespaceName());
		/** @var UrlAnnotation $urlAnnotation */
		$urlAnnotation = Reader::read($request);
		$data          = $this->fetchData($request, $reflectClassRequest, $urlAnnotation);

		$reflectClassName = new \ReflectionClass($namespace . $className);
		$instance         = $reflectClassName->newInstanceArgs([$request, $data, $urlAnnotation]);
		return call_user_func([$instance, 'execute']);
	}
1090873
public function transform(ApiRequest $request, ApiResponse $response, array $context = []): ApiResponse
	{
		if (isset($context['exception'])) {
			// Convert exception to json
			$content = Json::encode($this->extractException($request, $response, $context));
			if ($context['exception'] instanceof ClientErrorException || $context['exception'] instanceof ServerErrorException) {
				$response = $response->withStatus($context['exception']->getCode());
			} else {
				$response = $response->withStatus(500);
			}
		} else {
			// Convert data to array to json
			$content = Json::encode($this->extractData($request, $response, $context));
		}

		$response->getBody()->write($content);

		// Setup content type
		return $response
			->withHeader('Content-Type', 'application/json');
	}
137327
public static function exception(ApiException $exception)
    {
        $returnResponse = \Response::make($exception->jsonSerialize());

        $returnResponse->setStatusCode($exception->getStatusCode());

        return $returnResponse;
    }
1008325
public function execute(RestRequestModel $apiRequest)
    {
        $result = new ApiResultModel();

        list($controller, $action, $args) = $this->resolveController($apiRequest->getRoute(), $apiRequest->getPath());

        $actionReader = new ActionReader($controller);

        if ($apiRequest->getMethod() == 'OPTIONS') {
            $ack = $this->optionsAck($actionReader, $action);

            return $result
                ->setContent($this->serialize($ack))
                ->setJson(true)
                ->setHeaders(['Allow' => 'OPTIONS, GET, POST'])
                ->setStatusCode(200);
        }

        $ack = $this->callAction($actionReader, $apiRequest, $action, $args);

        return $result
            ->setContent($this->serialize($ack))
            ->setJson(true) // serialized ^
            ->setStatusCode($ack->getServerCode());
    }
1009440
public function hook(Request $request): JsonResponse
    {
        (new Collection($request->input('events', [])))
            ->filter(function ($event): bool {
                return Arr::get($event, 'name') === 'channel_vacated';
            })
            ->each(function (array $event): void {
                $this->storage->deleteSubscriber(
                    Arr::get($event, 'channel')
                );
            });

        return response()->json(['message' => 'okay']);
    }
823456
public static function toResponse($request, $response)
    {
        if ($response instanceof Responsable) {
            $response = $response->toResponse($request);
        }

        if ($response instanceof PsrResponseInterface) {
            $response = (new HttpFoundationFactory)->createResponse($response);
        } elseif ($response instanceof Model && $response->wasRecentlyCreated) {
            $response = new JsonResponse($response, 201);
        } elseif (! $response instanceof SymfonyResponse &&
                   ($response instanceof Arrayable ||
                    $response instanceof Jsonable ||
                    $response instanceof ArrayObject ||
                    $response instanceof JsonSerializable ||
                    is_array($response))) {
            $response = new JsonResponse($response);
        } elseif (! $response instanceof SymfonyResponse) {
            $response = new Response($response);
        }

        if ($response->getStatusCode() === Response::HTTP_NOT_MODIFIED) {
            $response->setNotModified();
        }

        return $response->prepare($request);
    }
469071
public function run(Request $request, Response $response) : Response {

		$strict = $this->getParam('STRICT_ROUTING');
		$case = $this->getParam('CASE_SENSITIVE');
		$method = $request->getMethod();
		$url = $request->getUri()->getPath();

		//Matching
		foreach($this->routes as $route) {
			if($route->match($url, $strict, $case) && $method == $route->getMethod()) {
				return $route->call($request, $response);
			} elseif($route->match($url, $strict, $case) && $method == 'HEAD') {
				$body = $response->getBody();
				$body->close();
				$response = $response->withBody($body);
				return $response;
			}
		}

		//Error
		$methods = array();
		foreach($this->routes as $route) {
			array_push($methods, $route->getMethod());
			if($route->match($url, $strict, $case) && $method != $route->getMethod() && in_array($method, self::$_METHODS))
				return call_user_func($this->httpErrors['405'], $request, $response);

			elseif($route->match($url, $strict, $case) && $method != $route->getMethod() && !in_array($method, self::$_METHODS))
				return call_user_func($this->httpErrors['400'], $request, $response);
		}

		if(!in_array($method, $methods) && !in_array($method, self::$_METHODS))
			return call_user_func($this->httpErrors['400'], $request, $response);
		else
			return call_user_func($this->httpErrors['404'], $request, $response);
		
	}
702309
protected function handlePayload(Request $request, Response $response, Payload $payload): Response
    {
        $handler = $this->getHandler($request);

        return $response
            ->withBody(Factory::newStream($handler->body($payload)))
            ->withHeader('Content-Type', $handler->type())
            ->withStatus($payload->getCode())
        ;
    }
1285830
public function send(Request $request)
    {
        $response    = new GetResponse();
        $httpRequest = $this->createHttpRequest($request);

        try {
            $httpResponse = $this->client->send($httpRequest);
            $code         = $httpResponse->getStatusCode();
        } catch (RequestException $e) {
            if ($e->getCode() == 404 && $request->notfoundOk) {
                return $response;
            }

            throw $e;
        }

        if ( ! isset($this->validResponseCodes[$code])) {
            throw RiakTransportException::unexpectedStatusCode($code);
        }

        $json    = $httpResponse->json();
        $context = isset($json['context']) ? $json['context'] : null;
        $value   = $json['value'];
        $type    = $json['type'];

        $response->type    = $type;
        $response->context = $context;
        $response->value   = $this->opConverter->fromArray($type, $value);

        return $response;
    }