WebApi 2 HelpPage using ResponseType attribute instead of SetActualResponseType

In my previous post, Using Microsoft ASP.NET Web API 2 Help Page – Part 2 I mentioned that in MVC5, the HelpPage API, you no longer to specify the response type as part of the HelpPageConfig.

This was simplier than I thought it would be.

Using this GitHub commit of the PolicyController, The Get methods have no attributes. Within HelpPageConfig, we have the following code:


config.SetActualResponseType(typeof(Core.Models.Policy),
    "Policy", "Get");

This line needs to be removed.

On the PolicyController, add the following attribute to the Get methods


[ResponseType(typeof(Policy))]

If required add a link to System.Web.Http;

Check the help page, and the samples are displayed correctly. Using Attributes just feels cleaner that adding multiple entries into the HelpPageConfig. Missing the attribute, you know that there will be a problem with the produced api documentation

Enhanced by Zemanta
Advertisements

My musing about anything and everything

Tagged with: , ,
Posted in Help Page, MotorDB, WebAPI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 9 other followers

%d bloggers like this: