简介
是dotNet core下基于Beetlex实现的一个高度精简化和高吞吐的HTTP API服务开源组件,它并没有完全实现HTTP SERVER的所有功能,而是只实现了在APP和WEB中提供数据服务最常用两个指令GET/SET,满足在应用实现JSON,PROTOBUF和MSGPACK等基于HTTP的数据交互功能,虽然是一个精简版本但针对SSL这方面的安全性还是支持。有牺牲就必然有收获,FastHttpApi作出这么大的精简必然在性能上有所收获取,经测试FastHttpApi在GET/POST这些数据交互的场景下性能和吞吐能力是Asp.net core集成的Kestrel的要优胜许多。
https://github.com/IKende/FastHttpApi
使用便利性
FastHttpApi虽然在HTTP方面作了大量的精简,但并没有为此增加了它使用的复杂度。FastHttpApi具备asp.net core webapi的便利性;应用人员只需要制定和webapi一样的方法即可,在使用过程中和写普通逻辑方法没有多大的区别。
定义一个控制器
控制器用来定义具体相应URL处理的方法,只需要在类上定义Controller属性即可把类中的Public方法提供给Http访问;方法参数来源于QueryString,当参数标记为BodyParameter的时候参数来源于Http Body.
[Controller] public class ControllerTest { // /hello?name= public string Hello(string name) { return DateTime.Now + " hello " + name; } // /add?a=&b= public string Add(int a, int b) { return string.Format("{0}+{1}={2}", a, b, a + b); } // /post?name= public object Post(string name, [BodyParameter] UserInfo data) { return data; } // /listcustomer?count public IList<Customer> ListCustomer(int count) { return Customer.List(count); } // /listemployee?count public IList<Employee> ListEmployee(int count) { return Employee.List(count); } // post /AddEmployee public Employee AddEmployee([BodyParameter]Employee item) { return item; } }
Filter定义
Filter是Controller处理方法的拦载器,通Filter可以对所有方法进行统一拦载处理,如权限日志等。
[Controller] [NotFoundFilter] public class ControllerTest { // /hello?name= [SkipFilter(typeof(NotFoundFilter))] [CustomFilter] public string Hello(string name) { return DateTime.Now + " hello

