-
-
Notifications
You must be signed in to change notification settings - Fork 175
Home
Henry edited this page Sep 10, 2019
·
22 revisions
'FastHttpApi'是基于Beetlex
扩展的轻量级高性能的HTTP服务组件,在提供简便的应用方式同时支持高效的吞吐处理能力,相对asp.net core webapi
性能提升可达到200%.
- 支持Linux,Windows等多平台部署
- 支持HTTPS,可制定更安全可靠的API服务
- 支持Websocket,服务同时兼容HTTP和WebSocket通讯协议
- 支持类方法的方式定义服务,让服务制定更简便
- 支持静态资源和热更新
- Asp.net core webapi
public class HomeController : Controller
{
public class JsonMessage
{
public string message { get; set; }
}
public string plaintext()
{
return "Hello, World!";
}
public object json()
{
return new JsonMessage { message = "Hello, World!" };
}
public List<Employee> Employees()
{
return DataHelper.Defalut.Employees;
}
public Employee Employee(int id)
{
Employee result = DataHelper.Defalut.Employees.Find(e => e.EmployeeID == id);
if (result == null)
result = new Employee();
return result;
}
public object Orders(int id, string customerid, int index, int size)
{
Func<Order, bool> exp = o => (id == 0 || o.EmployeeID == id)
&& (string.IsNullOrEmpty(customerid) || o.CustomerID == customerid);
int count = DataHelper.Defalut.Orders.Count(exp);
if (size == 0)
size = 10;
int pages = count / size;
if (count % size > 0)
pages++;
var items = DataHelper.Defalut.Orders.Where(exp).Skip(index * size).Take(size);
return items;
}
}
- FastHttpApi
[Controller(BaseUrl = "Home")]
public class Controller
{
public class JsonMessage
{
public string message { get; set; }
}
public object plaintext()
{
return new TextResult("Hello, World!");
}
public object json()
{
return new JsonResult(new JsonMessage { message = "Hello, World!" });
}
public List<Employee> Employees()
{
return DataHelper.Defalut.Employees;
}
[Get(Route = "{id}")]
public object Employee(int id)
{
Employee result = DataHelper.Defalut.Employees.Find(e => e.EmployeeID == id);
if (result == null)
result = new Employee();
return new JsonResult(result);
}
[Get(Route = "{id}")]
public object Orders(int id, string customerid, int index, int size)
{
Func<Order, bool> exp = o => (id == 0 || o.EmployeeID == id)
&& (string.IsNullOrEmpty(customerid) || o.CustomerID == customerid);
int count = DataHelper.Defalut.Orders.Count(exp);
if (size == 0)
size = 10;
int pages = count / size;
if (count % size > 0)
pages++;
var items = DataHelper.Defalut.Orders.Where(exp).Skip(index * size).Take(size);
return new JsonResult(items);
}
}
- 完整测试代码
https://github.com/IKende/FastHttpApi/tree/master/PerformanceTest/Beetlex_VS_AspCore_webapi