Skip to content

Instantly share code, notes, and snippets.

@pedroreys
Created March 6, 2012 14:44
Show Gist options
  • Save pedroreys/1986630 to your computer and use it in GitHub Desktop.
Save pedroreys/1986630 to your computer and use it in GitHub Desktop.
Using CreateResponse
public class Person : IApiResource
{
public int Id { get; set; } //whatever property is going to be used in the Get(int id) method in PeopleController
public void SetLocation(ResourceLocation location)
{
location.SetInController<PeopleController>(x => x.Get(Id));
}
}
// In the controller
public class PeopleController : ApiController
{
public HttpResponseMessage<Person> Create(Person person)
{
_repository.Save(person);
return new CreateResponse(person);
}
}
// this should result in a response:
HTTP 1.1 201 Created
//other headers
Location: http://api.contoso.com/people/1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment