Example #1
0
 public function testSetCreated()
 {
     $response = new Response();
     $location = 'http://sonno.360i.com';
     $response->setCreated($location);
     $this->assertEquals($response->getStatusCode(), 201);
     $this->assertEquals($response->getHeader('Location'), $location);
 }
Example #2
0
 /**
  * This is the first example in this Resource that doesn't use a GET
  * annotation. Here, the resource will handle HTTP POST requests that are
  * sent in 'application/xml' form. Also, this method will also handle
  * requests to the same Path as the method above. The router determines
  * what resource method to call, not only based on the Path annotation, but
  * also what the HTTP method is as well as the Produces annotations.
  *
  * Another annotation that's being introduced here is the Consumes
  * annotation. This specifies what type of content it can accept based on
  * what the client's "Content-Type" header is set to. If the client
  * specifies a type not supported by a resource, a 415 Unsupported Media
  * Type is set, and this function is never executed.
  *
  * Looking at the function body, we're also using the property that was
  * injected via the Context annotation with a Sonno\Http\Request\Request
  * object. We use this object to pull the raw XML data out of the request
  * body.
  *
  * Finally, take notice that the function is returning a Response object.
  * But before the object is returned the method "setCreated" is called.
  * This will set the location header with the argument passed into the
  * constructor as well as set the response code to 201. There are several
  * other convenience methods on the Response object that can be used for
  * similar purposes.
  *
  * @POST
  * @Path("/users")
  * @Consumes({"application/xml"})
  */
 public function saveUserXml()
 {
     // Retrieve the request body.
     $data = $this->_request->getRequestBody();
     // ... Do some processing of $data, then save it...
     $response = new Response();
     return $response->setCreated('http://example.sonno.dev/users/10');
 }