In this recipe, we will demonstrate how to self-host an ASP.NET web API. A web API gives us the flexibility to host our web API in our process, also called self-hosting.
In order to use this recipe you should have Visual Studio 2012 and ASP.NET MVC 4 installed (the latter includes the ASP.NET Web API).
Next we are going to self-host our web API.
Create a new console application project and name it
WebAPISelfHosted
.Open the NuGet package manager, which you can launch from the Tools menu, select Library Package Manager, and click on Manage NuGet Packages for Solution.
Select the online packages, and look for Microsoft ASP.NET Web API Self Host and click on Install as shown in the following screenshot:
We will add a class named
Booksmodel.cs
with the following code:public class BookModel { public int Id { get; set; } public String Title { get; set; } public String Description { get; set; } public bool IsOnSale ...