In this recipe, we will see how to expose a basic service and some data through HTTP with the ASP.NET web API.
In order to use this recipe, you should have Visual Studio 2012 and ASP.NET MVC 4 installed (the latter one includes the ASP.NET web API).
Next we are going to create a web API:
To start, open Visual Studio 2012, select the web category from the visual C# categories and use the ASP.NET MVC 4 Web Application template to create a new project. Name it
WebAPI101
.On the New ASP.NET MVC 4 Project dialog select the Web API template and click on the OK button.
The following project structure will be created for us:
In the
Models
folder we will add a class, name itBooksmodel.cs
, and introduce the following code:public class BookModel { Public int Id { get; set; } public String Title { get; set; } public String Description { get; set; } public bool IsOnSale { get; set; } public int BookRating { get; set; } public double BookPrice...