Created
April 1, 2013 15:52
-
-
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)
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
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