public function testBuildingWithCustomStatusCodeAndHeaders()
 {
     $response = new Response('test');
     $response->statusCode(302);
     $response->header('Foo', 'Bar');
     $this->assertEquals('Bar', $response->headers->get('Foo'));
     $this->assertEquals(302, $response->getStatusCode());
 }
Example #2
0
 /**
  * Respond with an accepted response and associate a location and/or content if provided.
  *
  * @param null|string $location
  * @param mixed       $content
  *
  * @return \Dingo\Api\Http\Response
  */
 public function accepted($location = null, $content = null)
 {
     $response = new Response($content);
     $response->setStatusCode(202);
     if (!is_null($location)) {
         $response->header('Location', $location);
     }
     return $response;
 }
Example #3
0
 /**
  * Respond with a created response and associate a location if provided.
  *
  * @param null|string $location
  *
  * @return \Dingo\Api\Http\Response
  */
 public function created($location = null)
 {
     $response = new Response(null);
     $response->setStatusCode(201);
     if (!is_null($location)) {
         $response->header('Location', $location);
     }
     return $response;
 }
Example #4
0
 /**
  * Override parent method
  *
  * @override
  *
  * @param null     $location
  * @param \Closure $data
  * @return Response
  *
  */
 public function created($location = null, \Closure $data = null)
 {
     list($item, $transformer, $headers) = $data();
     $class = get_class($item);
     $binding = $this->transformer->register($class, $transformer);
     $response = new Response($item, 201, $headers, $binding);
     if (!is_null($location)) {
         $response->header('Location', $location);
     }
     return $response;
 }