Framework Overview
Ezhttp is a framework of temporary spur conceived and developed to simplify CS light application development process. The development language is C #.
Common HTTP-based application development is basically restful, the client call encapsulation requires manual code, even if the use of the three-party library, is not to fill a relative path.
The former webservice can automatically generate client calls when compiled by reference, but the server must be online to be updated.
Why can't we create an elegant calling method, such as a contract-based interface. And this interface is interface in the C # language instead of a URL address.
Framework uses
Imagine such an example,
1, there are three items, respectively, the service side, client, interface.
2. The service side references the interface project and implements the interface method.
3. The client references the interface and obtains a proxy object for an interface through the client object of the Ezhttp framework.
The client can now get the returned value through an interface call method. This value is the value returned by that method of the class that the service side implements for the interface method.
As a result, client development is generally refreshing as WebService generates a reference agent, and the shared interface can be updated synchronously.
Design ideas
Creates a client proxy object through the framework, encapsulating the client call as an HTTP call and providing the return value with the appropriate processing to the method return value.
The framework implementation base is based on the unique ID of the objects in the generated class library.
The process is as follows:
1, before initializing the client's call, get the metadata from the server (including the interface and implementation of the type ID mapping).
2. The service side obtains and caches metadata through reflection and returns it to the client.
3. When the client invokes an interface method, the framework submits the metadata and arguments to the server through the HTTP encapsulation method.
4, the service side to find the interface implementation class, after the instantiation of the corresponding method, get the return value after the write HTTP reply.
5, the client resolves the reply and handles the call error.
Advanced Support
Interface supports designing methods that return values to task or task<t>
Provides an interface for transport streams that clients can use to return stream data, such as files, from the server.
Why provide a separate stream transport interface without using a normal interface method with a return value of byte[]?
When the stream length is large, the byte[] data of the normal interface is fully in memory and consumes the server resources.
The independently designed stream transport interface uses buffers to read and write data. Avoids a crash or a sharp increase in server load due to the inability of the streaming data program to process.
Development Roadmap
Support Interface Dependency Injection
Supports interceptors (filters) for interface implementations and interface method implementations
Code Preview
Service side
New ezhttp.ezserver (); Server. Start ($"http://127.0.01:8000/");
Interface:
Public Interfaceitranslateapi{/// <summary>///translation (in English translation)/// </summary>/// <param name= "input" ></param>/// <returns></returns>stringTranslate (stringinput);/// <summary>///translating (in English) and extracting keywords/// </summary>/// <param name= "input" ></param>/// <param name= "Count" ></param>/// <param name= "Weightout" ></param>/// <returns></returns>stringTranslateandgetkeywords (stringInputintCountBOOLweightout);}
Interface implementation:
Public classTranslateImpl:EzHttp.EzHandler, Itranslateapi { Public stringTranslate (stringinput) { if(string. IsNullOrEmpty (Input)) {Throw NewException ("input can not is null"); } returnForm1.Instance.Translate (input); } Public stringTranslateandgetkeywords (stringInputintCountBOOLweightout) { if(string. IsNullOrEmpty (Input)) {Throw NewException ("input can not is null"); } varOutput =Translate (input); if(string. IsNullOrEmpty (Output)) {Throw NewException ("translate result is null."); } if(! Keywordextract.nlpir_init (@".\",0))//give the path to the data file, and take care to modify it according to the actual situation. { Throw NewException ("Keyword Extraction service init error"); } varPTR =keywordextract.nlpir_getkeywords (output, count, weightout); returnMarshal.ptrtostringansi (PTR); } }
Client Calls
Ezclient.initialize ("http://127.0.0.1:8000/"); var api = Ezclient.proxyfactory.getproxy<itranslateapi>(); API. Translate (System.IO.File.ReadAllText ("input.txt"));
Participation in the framework discussion: 590883722
Using EZHTTP framework to develop CS light application based on HTTP protocol