Skip to content

Instantly share code, notes, and snippets.

@pedroreys
Created March 6, 2012 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pedroreys/1986568 to your computer and use it in GitHub Desktop.
Save pedroreys/1986568 to your computer and use it in GitHub Desktop.
CreateResponse
public class CreateResponse : HttpResponseMessage
{
public CreateResponse()
{
StatusCode = HttpStatusCode.Created;
}
public CreateResponse(IApiResource resource) :this()
{
var location = new ResourceLocation();
resource.SetLocation(location);
Headers.Location = location.Location;
}
}
public class CreateResponse<T> : HttpResponseMessage<T>
{
public CreateResponse() : base(HttpStatusCode.Created)
{
}
public CreateResponse(T resource) : base(resource, HttpStatusCode.Created)
{
if (resource is IApiResource)
{
var apiResource = resource as IApiResource;
var resourceLocation = new ResourceLocation();
apiResource.SetLocation(resourceLocation);
Headers.Location = resourceLocation.Location;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment