Designing Evolvable Web APIs with ASP.NET
by Glenn Block, Pablo Cibraro, Pedro Felix, Howard Dierking, Darrel Miller
Chapter 11. Hosting
Web API meets its downstairs neighbors.
Chapter 4 divided the ASP.NET Web API processing architecture into three layers: hosting, message handler pipeline, and controller handling. This chapter addresses in greater detail the first of these layers.
The hosting layer is really a host adaptation layer, establishing the bridge between the Web API processing architecture and one of the supported external hosting infrastructures. In fact, Web API does not come with its own hosting mechanism. Instead, it aims to be host independent and usable in multiple hosting scenarios.
In summary, the host adapter layer is responsible for the following tasks:
-
Creating and initializing the message handler pipeline, encapsulated in an
HttpServerinstance. - Receiving HTTP requests from the underlying hosting infrastructure, typically by registering a callback function.
-
Transforming HTTP requests from their native representation (e.g., ASP.NET’s
HttpRequest) intoHttpRequestMessageinstances. - Pushing these instances into the message handler pipeline, effectively initiating the Web API request processing.
-
When a response is produced and returned, the hosting adapter transforms the returned
HttpResponseMessageinstance into a response representation native to the underlying infrastructure (e.g., ASP.NET’sHttpResponse) and delivers it to the underlying hosting infrastructure.
In version 1.0, two hosting adapters were available: web hosting and self-hosting. The former hosting option ...