Skip to content

Instantly share code, notes, and snippets.

@pcibraro
Created April 1, 2013 15:52
Show Gist options
  • Save pcibraro/5285734 to your computer and use it in GitHub Desktop.
Save pcibraro/5285734 to your computer and use it in GitHub Desktop.
AttributeRouting in ASP.NET Web API for Hypermedia Web APIs. Links user user/picture (It's a child resource)
RoutePrefix("user")]
public class UserController : ApiController
{
public UserController()
{
}
[GET("", RouteName="GetUser")]
public UserProfile Get()
{
...
var resource = new UserProfile
{
Email = user.Email
};
resource.Links.Add(new Link
{
Rel = "picture",
Href = this.Url.Link("GetUserPicture", new {})
});
resource.Links.Add(new Link
{
Rel = "myexercises",
Href = this.Url.Link("GetMyExercises", new { date = "?"})
});
return resource;
}
[GET("picture", RouteName = "GetUserPicture")]
public async Task<HttpResponseMessage> GetPicture()
{
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment