Chapter 8. Creating and Hosting Our First ASP.NET Web API

In this chapter we will cover:

  • Creating our first ASP.NET web API
  • Implementing a CRUD ASP.NET web API
  • Setting up a self-hosted ASP.NET web API

Introduction

.NET 4.5 introduces the capability to create ASP.NET web APIs. This is brought to us by ASP.NET MVC4. Basically, the ASP.NET web API is a framework that enables developers to easily build HTTP services. This makes the framework a good fit to build RESTful applications over .NET 4.5.

An important point is that, since these services are being exposed over HTTP, we can integrate them with almost any client device and technology in the market, which makes them extremely useful.

ASP.NET web APIs provide support for:

  • A modern HTTP programming model, allowing direct access and manipulation of HTTP requests and responses.
  • Content negotiation, which helps determine the proper format for the data that the ASP.NET Web API returns. JSON and XML are supported out of the box and customizations for our own formats and structures are also allowed.
  • Query composition through OData conventions, supporting OData queries automatically out of the box when we return IQueryable<T> from our ASP.NET web API methods.
  • Model binding, providing them directly on an HTTP request, and converting them into .NET objects.
  • Self-hosting.

ASP.NET web API adds more punch with coding features such as routing capabilities support, testability additions, IoC, and more.

In the following sections we will see how to create our first ASP.NET web API, create a CRUD with it, and explore its self-hosting option.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset