Overview of WebApi framework and webapi framework
The WebApi framework can be divided into three layers: The management layer, the message processing program management layer, and the Controller processing layer.
I. Hosting layer:
That is, the Host is a WebAPI Host, such as a console or a Windows service.
Boarding mode.
1. Custom hosting.
2. Self-managed.
3. Web Hosting
Owin boarding, such as Katana, creates a WebApi layer on an Owin-compatible server to generate HttRequestMessage. After the WebApi is processed, the HttpResponseMessage is written to the Owin context.
Objects related to webapis (carriers responsible for data exchange between frameworks and external tables, managed encapsulation of Http packets ):
1) HttRequestMessage
Request object encapsulated by WebAPI (resolved from the Http request package, corresponding to the previous HttpWebRequest, in System. Net. Http)
2) HttpResponseMessage
Returned objects encapsulated by WebAPI (the http return request object generated from the managed code is converted from the framework to the http response package ).
Ii. Message Processing Program Hosting Layer
HttpServer: WebApi message processing channel, where you can add extended processing programs, such as proxies, gateways, cache processing, and access records.
Core object: HttpMessageHandler interface.
The DelegatingHandler abstract class is used to construct a processing chain and pass through the InnerHanlder attribute. It is implemented in the responsible chain mode.
Process:
1 HttpRequestMessage
2. myDelegatingHandler1
MyDelegatingHandler2
MyDelegatingHandler3
3. Route distribution processing program
1) Select the controller (HttpRoutingDispacher)
4. Control the distribution processing program
1) controller selection (HttpControllerDispacher)
ControllerSelector (engineering mode implementation) => ControllerDescription (engineering mode implementation ).
2) handle errors.
5) HttpResponseMessage
4, 3, 2, and 5.
3. Controller Processing Layer
1. Locate the method to be requested in the Controller Based on the context information;
ApiController
Implement the IHttpController interface.
Function: identity authentication, authorization authentication, and model check.
1) Format
2) model binding
Parameter ing is an object model Hotel hotel
Media type resolution.
3) filter.
IActionFilter interface, permission verification, etc.
----------------
Core objects:
HttpMessageHandler |
Core class. The request processing is implemented in SendAsync. The response processing is completed by the return type Task <HttpResponseMessage>. |
HttpRequestMessage |
Content Attributes encapsulate Http Subject Information |
HttpResponseMessage |
StatusCode and ReasonPhrase attributes indicate the response status code and description. |
DelegatingHandler |
It is used to build a processing chain and pass it through the InnerHanlder attribute. It is the implementation of the responsibility chain model. |
HttpServer |
The Dispatcher attribute points to the final distributor object. The Configuration attribute contains all the Configuration information. |
HttpConfiguration |
Global configuration information: management layer, message processing program pipeline layer, controller processing layer, and other configurations. |