Skip to content

Instantly share code, notes, and snippets.

@mxrss
Created December 4, 2013 23:10
Show Gist options
  • Save mxrss/7797301 to your computer and use it in GitHub Desktop.
Save mxrss/7797301 to your computer and use it in GitHub Desktop.
Add API help link to web api.
protected async override System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
var baseHandler = await base.SendAsync(request, cancellationToken);
var content = await baseHandler.Content.ReadAsAsync<ResponseBase>();
if (content != null)
{
var apiDescription = request.GetActionDescriptor().Configuration.Services.GetApiExplorer().ApiDescriptions.Where(x => x.ActionDescriptor == request.GetActionDescriptor()).SingleOrDefault();
if (apiDescription != null)
{
var link = apiDescription.GetFriendlyId();
var returnLink =request.GetUrlHelper().Link("HelpPage_Default", new
{
action="api",
apiId = link
});
content.HelpLink = returnLink;
}
}
return baseHandler;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment