Chlodny series Day 5: Brief: What is ASP.NET Web API?

ASP.NET Web API is the new product born from WCF for jQuery.  Web API allows services to be created over HTTP rather then utilizing a service contract (SOAP or WS). Web API  creates an avenue for developers to expose data from the server to any number of clients.  Web API allows for the development of RESTful services.  Representational State Transfer (or REST) it is an architecture, it is not something new.  REST can sometimes also be referred to as HTTP services because it supports four primary HTTP verbs

  • POST : Push data to the service and create a new entity
  • PUT : Update data in an existing entity
  • GET : Retrieve entity or entities
  • DELETE : Delete an entity

Some advantages of REST (HTTP) services over SOAP from a web application perspective.

  • REST is an application-level protocol, this is one of the reasons is supports the verbs mentioned above.
  • SOAP has to maintain a service contract dictionary while REST specifies the contract in the Uniform Interface.
  • Headers can be more meaningful and descriptive, including improved definition of content type, cache information, and security information.
  • Messages can be anything requested: HTML, plain XML, JSON, binary files
  • Information paths and actions are identified by uniform resource identifier (or URI)

What does ASP.NET Web API offer to .NET Developers.

  • Create Web API’s that can support a broad range of client applications, (MVC, Web Forms, PHP, JavaScript and mobile applications to name a few)
  • HTTP programming model: strongly typed HTTP object model  on the server and the client.  .NET clients can access the new HttpClient API formatters that enhances communication between client and server.
  • Content negotiation:  Allows the client and server to determine the correct format for the data to be transmitted in.  Default support for JSON, XML and form URL-encoded formats.  This feature is also extensible to allow the default formatters to be changed or new ones added.
  • Query composition: Allows queries to be returned as type IQueryable<T>, this enables applications to support the OData URL convention which can make paging and sorting easier.
  • Model binding and validation: Adds the same model binding and validation support that are currently in ASP.NET MVC.
  • Routes: Adds the same routing functions that are currently in ASP.NET MVC.
  • Filters: Allows filters to be created that enable encapsulation and applying cross-cutting behavior.
  • Improved testability: HttpRequestMessage and HTTPResponseMessage can be an instance, allows some unit testing without a Mocking framework
  • IoC support: uses the ASP.NET MVC service locator pattern to resolve dependencies.
  • Flexible Hosting:  Web APIs can be hosted in ASP.NET MVC and ASP.NET Web Forms.
This entry was posted in Entity Framework, MVC, Web and tagged , , , , . Bookmark the permalink.