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
// bind all commands decorated with IFromUriCommand from the Uri. | |
config.ParameterBindingRules.Insert(0, | |
desc => typeof(IFromUriCommand).IsAssignableFrom(desc.ParameterType) | |
? new FromUriAttribute().GetBinding(desc) | |
: null); |
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 ResourceLinksActionFilterAttribute : ActionFilterAttribute | |
{ | |
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) | |
{ | |
ResourceModel payload; | |
if (actionExecutedContext.Response.TryGetContentValue<ResourceModel>(out payload)) | |
{ | |
payload.BuildResourceLinks(actionExecutedContext.Request); | |
} | |
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
{ | |
page:2, | |
pageSize:1, | |
totalCount:3, | |
totalPages:3, | |
hasPreviousPage:true, | |
hasNextPage:true, | |
results:[ | |
{ | |
id:193, |
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
{ | |
"page":1, | |
"pageSize":1, | |
"totalCount":4, | |
"totalPages":4, | |
"hasPreviousPage":false, | |
"hasNextPage":true, | |
"results":[ | |
{ | |
"id":129, |
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 interface IFoo | |
{ | |
} | |
public interface IFooCollection | |
{ | |
IEnumerable<IFoo> Items { get; } | |
} |
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
/sites -- get all sites | |
/sites/65 -- get site with id 65 | |
/sites/65/posts -- get posts from site with id 65 | |
/sites/65/posts/10 -- get post with id 10 from site with id 65 | |
/sites/65/posts/tags -- get a list of tag counts for all posts from site with id 65 | |
/sites/65/posts/tags/web-api -- get all posts from site with id 65 tagged with web-api | |
query parameters: |
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 AtomPubMediaFormatter : MediaTypeFormatter | |
{ | |
private const string Atom = "application/atom+xml"; | |
public AtomPubMediaFormatter() | |
{ | |
SupportedMediaTypes.Add(new MediaTypeHeaderValue(Atom)); | |
this.AddQueryStringMapping("format", "atom", Atom); | |
} |
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
/// <summary> | |
/// Page Resource API. | |
/// </summary> | |
public class PagesController : ApiControllerBase | |
{ | |
/// <summary> | |
/// Get pages from the specified site. | |
/// </summary> | |
/// <param name="siteId">The site identifier.</param> | |
/// <param name="command">A command containing result paging parameters.</param> |
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
var config = new HttpConfiguration(); | |
config.Routes.MapHttpRoute("Foo", "foo/{id}", new { controller = "foo" }); | |
config.Routes.MapHttpRoute("Bar", "bar/{id}", new { controller = "bar" }); | |
var requestMessage = new HttpRequestMessage(HttpMethod.Get, "/"); | |
var vp = config.Routes.GetVirtualPath(requestMessage, "Foo" , new Dictionary<string,object> { { "controller", "foo" }, { "id", 10 } }); | |
Console.WriteLine(vp); | |
Console.ReadLine(); |
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 static class UrlHelperExtensions | |
{ | |
public static string Link(this UrlHelper urlHelper, object values) | |
{ | |
var config = urlHelper.Request.GetConfiguration(); | |
var routeValues = new HttpRouteValueDictionary(values); | |
routeValues.Add("httproute", true); // required to define a web api route | |