Created
December 4, 2013 23:10
-
-
Save mxrss/7797301 to your computer and use it in GitHub Desktop.
Add API help link to web api.
This file contains 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
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