For a task at work, I needed a mock WebApi for mimicking behavior of 3rd party API, that is not accessible from my machine. Sure enough I proceeded using line of least possible resistance and selected ASP.NET MVC Web Application template and WebAPI and ended up with bloated project that scared the life out of me when I just looked at it. Seriously, Microsoft, you couldn’t do a simpler template? I am pretty sure, that having all sorts MVC thingies installed helps, although, I am not completely sold on EntityFramework that sneaks in as well. But I digress.

Without further ado, I present you minimal WebAPI. A project that contains only what it needs to, to behave as WebAPI and nothing more. Below, I will lead you step by step through the process of creating one yourself, but you can also clone a repository from GitHub. Be careful though, as solution only supports .NET 4.6.x.

Step 1: Create empty web application

Open Visual studio and select ASP.NET MVC Web Application, select a name and location of your solution and click OK.  A dialog, prompting you to select additional options will show. Select Empty and uncheck every checkbox. After clicking OK, you will end up with empty web application solution. I know you might feel tempted to select WebAPI. Don’t. The end result will be nearly the same as selecting Web API from additional options.

Step 2: Add Web API to the project

First things, well, first. You could do it another way, but the easiest way is to fire up NuGet Pacakage Management Console and type the following command:

or, if you are using older .NET version than 4.5.x:

This will install the following packages:

  • Microsoft.AspNet.WebApi,
  • Microsoft.AspNet.WebApi.Client,
  • Microsoft.AspNet.WebApi.Core,
  • Microsoft.AspNet.WebApi.WebHost and
  • Newtonsoft.Json.

Step 3: Add Web API configuration

Now you need to add Web API configuration. Create new folder named “App_Start”. I guess it could be named differently, but since templates put configs in “App_Start” folder, I stuck with that solution. In this folder (however you choose to name it), add a class named WebApiConfig and (for ease of use) make sure that namespace does not contain your folder name. This class should look like this:

Or, for users of .NET older than 4.5.x:

Now, you only need to add Global.asax file and enable Web API configuration. Code of Global.asax should look something like this:

Again, for .NET older than 4.5.x, you need to do things a tad differently:

And… you are done. Now, you should follow de-facto standard and create a folder named Controllers for all your Api controllers. Other than that, this is it. As said above, you can clone repository or look at code on GitHub for further reference.