While investigating migrating the API code in our application at work from the nearly-abandoned Jayrock RPC framework to the more widespread and well-supported ASP.NET WebAPI, I noticed that there was one nice-to-have that Jayrock enjoyed over WebAPI – it has a built-in automated tester which enables you to compose and submit AJAX requests to your API endpoints.

Well, I thought, certainly such a thing should be possible for WebAPI as well. Enter WebAPI Test-O-Matic! I found that there are is a super-convenient ApiExporer class included in the box with WebAPI. This is what WebAPI uses to generate it’s built-in “help pages.” This made it really easy to sniff-out and generate testing for all the configured WebAPI endpoints in a given ASP.NET application.

To use WebAPI Test-O-Matic, all you have to do is register the HTTP Handler in your ASP.NET application, like this:

      <remove name="WebApiTestOMatic" />
      <add name="WebApiTestOMatic" path="apitest.ashx" verb="*" type="WebApiTestOMatic.Handler, WebApiTestOMatic" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    <validation validateIntegratedModeConfiguration="false" />

Also make sure that MVC/WebAPI are configured to ignore the route to WebAPI Test-O-Matic:

public static void RegisterRoutes(RouteCollection routes)

        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }

That’s it! You should now be able to hit the URL configured in your web.config for the HTTP Handler above. This will give you a nice UI for testing your WebAPI controllers and actions:

WebAPI Test-O-Matic screenshot

The HTTP handler is entirely self-contained, so you don’t need to include any other files in your project other than the DLL. It does include client-side references to Bootstrap and jQuery from the Microsoft Ajax Content Delivery Network, which keeps the DLL really small as I don’t have to bundle those in.

You can view and contribute to the project on GitHub, or install it using NuGet.

Let me know what you think!