/** * Prepare a response by transforming and formatting it correctly. * * @author Morten Rugaard <*****@*****.**> * * @param mixed $response * @param \Dingo\Api\Http\Request $request * @param string $format * @return \Nodes\Api\Http\Response */ protected function prepareResponse($response, DingoRequest $request, $format) { if ($response instanceof IlluminateResponse) { $response = Response::makeFromExisting($response); } if ($response instanceof Response) { // If we try and get a formatter that does not exist we'll let the exception // handler deal with it. At worst we'll get a generic JSON response that // a consumer can hopefully deal with. Ideally they won't be using // an unsupported format. try { $response->getFormatter($format)->setResponse($response)->setRequest($request); } catch (NotAcceptableHttpException $exception) { return $this->exception->handle($exception); } $response = $response->morph($format); } if ($response->isSuccessful() && $this->requestIsConditional()) { if (!$response->headers->has('ETag')) { $response->setEtag(md5($response->getContent())); } $response->isNotModified($request); } return $response; }
/** * Respond with a no content response. * * @author Morten Rugaard <*****@*****.**> * * @return \Nodes\Api\Http\Response */ public function noContent() { $response = new Response(null); return $response->setStatusCode(204); }
/** * Set response static instances. * * @return void */ protected function setResponseStaticInstances() { NodesHttpResponse::setFormatters(prepare_config_instances(config('nodes.api.response.formats'))); NodesHttpResponse::setTransformer($this->app['api.transformer']); NodesHttpResponse::setEventDispatcher($this->app['events']); }