Created
March 6, 2012 14:44
-
-
Save pedroreys/1986630 to your computer and use it in GitHub Desktop.
Using CreateResponse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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