Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
F

FastHttpApi

> 编程语言
Open source

a lightweight and high-performance http/websocket service component in the dotnet core platform that supports TLS.

654 stars0 likes1 views
WebsiteGitHub

About

a lightweight and high-performance http/websocket service component in the dotnet core platform that supports TLS.

BeetleX.FastHttpApi is a lightweight and high-performance HTTP service component in the dotnet core platform that supports WebSocket and SSL.

samples

[https://github.com/beetlex-io/BeetleX-Samples]

Web Framework Benchmarks

Round 20

Using

Install BeetleX.FastHttpApi

Install-Package BeetleX.FastHttpApi

Base sample code

…

Url Map

csharp
mApiServer.Map("/", (ctx) =>
{
    ctx.Result(new TextResult("map /"));
});

mApiServer.Map("/user/{id}", async (ctx) =>
{
    ctx.Result(new TextResult((string)ctx.Data["id"]));
});

Url rewrite

csharp
mApiServer.UrlRewrite.Add("/api/PostStream/{code}/{datacode}", "/api/PostStream");
mApiServer.UrlRewrite.Add("/api/PostStream/{code}", "/api/PostStream");
mApiServer.UrlRewrite.Add(null, "/gettime", "/time", null);

Action route

csharp
[RouteMap("/map/{code}")]
[RouteMap("/map/{code}/{customer}")]
public object Map(string code, string customer)
{
    return new { code, customer };
}

Hosting and DI services

Install-Package BeetleX.FastHttpApi.Hosting

…

Windows service

csharp
class Program
{
    private static HttpServer mServer;

    static void Main(string[] args)
    {
        mServer = new HttpServer(80);
        mServer.IsWindowsServices = true;
        mServer.Setting((service, option) =>
        {
            option.LogToConsole = true;
            option.WriteLog = true;
            option.LogLevel = BeetleX.EventArgs.LogType.Info;
        });
        mServer.RegisterComponent();
        mServer.Run();
    }
}
[Controller]
public class Home
{
    public object Hello(string name)
    {
        return $"hello {name}";
    }
}

EntityFrameworkCore extensions

BeetleX.FastHttpApi.EFCore.Extension

…

Setting https

  • HttpConfig.json
 "SSL": true,
 "CertificateFile": "you.com.pfx",
 "CertificatePassword": "******",
  • Code
csharp
mApiServer.ServerConfig.SSL=true;
mApiServer.ServerConfig.CertificateFile="you.com.pfx";
mApiServer.ServerConfig.CertificatePassword="******";

Defined result

  • Text result
csharp
    public class TextResult : ResultBase
    {
        public TextResult(string text)
        {
            Text = text == null ? "" : text;
        }
        public string Text { get; set; }
        public override bool HasBody => true;
        public override void Write(PipeStream stream, HttpResponse response)
        {
            stream.Write(Text);
        }
    }

Download result

csharp
        public object DownloadImport(string id)
        {
           
            Dictionary result = new Dictionary();
            return new DownLoadResult(Newtonsoft.Json.JsonConvert.SerializeObject(result), $"test.json");
        }
  • Use
csharp
        public object plaintext()
        {
            return new TextResult("Hello, World!");
        }

Cookies

csharp
        public object SetCookie(string name, string value, IHttpContext context)
        {
            Console.WriteLine(context.Data);
            context.Response.SetCookie(name, value);
            return $"{DateTime.Now}{name}={value}";
        }

        public string GetCookie(string name, IHttpContext context)
        {
            Console.WriteLine(context.Data);
            return $"{DateTime.Now} {name}= {context.Request.Cookies[name]}";
        }

Header

csharp
        public void SetHeader(string token,IHttpContext context)
        {
            context.Response.Header["Token"]=token;
        }

        public string GetHeader(string name, IHttpContext context)
        {
            return  context.Request.Header[name];
        }

Data bind

  • Url

/hello?name=xxxor/hello/henry

csharp
        [Get(Route = "{name}")]
        public object Hello(string name, IHttpContext context)
        {
            return $"hello {name} {DateTime.Now}";
        }

/SetValue?id=xxx&value=xxxxor/SetValue/xxx-xxx

csharp
        [Get(Route = "{id}-{value}")]
        public object SetValue(string id, string value, IHttpContext context)
        {
            return $"{id}={value} {DateTime.Now}";
        }
  • Json

{"name":"xxxx","value":"xxx"}

csharp
        [Post]
        [JsonDataConvert]
        public object Post(string name, string value, IHttpContext context)
        {
            Console.WriteLine(context.Data);
            return $"{name}={value}";
        }

or

csharp
        [Post]
        [JsonDataConvert]
        public object Post(Property body, IHttpContext context)
        {
            Console.WriteLine(context.Data);
            return $"{body.name}={body.value}";
        }
  • x-www-form-urlencoded

name=aaa&value=aaa

csharp
        [Post]
        [FormUrlDataConvert]
        public object PostForm(string name, string value, IHttpContext context)
        {
            Console.WriteLine(context.Data);
            return $"{name}={value}";
        }
  • multipart/form-data
csharp
        [Post]
        [MultiDataConvert]
        public object UploadFile(string remark, IHttpContext context)
        {
            foreach (var file in context.Request.Files)
                using (System.IO.Stream stream = System.IO.File.Create(file.FileName))
                {
                    file.Data.CopyTo(stream);
                }
            return $"{DateTime.Now} {remark} {string.Join(",", (from fs in context.Request.Files select fs.FileName).ToArray())}";
        }
  • Read stream
csharp
        [Post]
        [NoDataConvert]
        public object PostStream(IHttpContext context)
        {
            Console.WriteLine(context.Data);
            string value = context.Request.Stream.ReadString(context.Request.Length);
            return value;
        }

Filter

  • Defined filter
csharp
    public class GlobalFilter : FilterAttribute
    {
        public override bool Executing(ActionContext context)
        {
            Console.WriteLine(DateTime.Now + " globalFilter execting...");
            return base.Executing(context);
        }
        public override void Executed(ActionContext context)
        {
            base.Executed(context);
            Console.WriteLine(DateTime.Now + " globalFilter executed");
        }
    }
  • Use
csharp
        [CustomFilter]
        public string Hello(string name)
        {
            return DateTime.Now + " hello " + name;
        }

or

csharp
    [Controller]
    [CustomFilter]
    public class ControllerTest
    {
    
    }
  • Skip filter
csharp
        [SkipFilter(typeof(GlobalFilter))]
        public string Hello(string name)
        {
            return DateTime.Now + " hello " + name;
        }

Parameters validation

csharp
public bool Register(
      [StringRegion(Min = 5)]string name,
      [StringRegion(Min = 5)]string pwd,
      [DateRegion(Min = "2019-1-1", Max = "2019-2-1")]DateTime dateTime,
      [EmailFormater]string email,
      [IPFormater]string ipaddress,
      [NumberRegion(Min = 18, Max = 56)]int age,
      [DoubleRegion(Min = 10)]double memory
                  )
        {
           return true;
        }

Async action

csharp
        [Get(Route = "{name}")]
        public Task Hello(string name)
        {
            string result = $"hello {name} {DateTime.Now}";
            return Task.FromResult(result);
        }

        public async Task Wait()
        {
            await Task.Delay(2000);
            return $"{DateTime.Now}";
        }

Cross domain

csharp
        [Options(AllowOrigin = "www.ikende.com")]
        public string GetTime(IHttpContext context)
        {
            return DateTime.Now.ToShortDateString();
        }

Websocket

  • Server
…
  • Hello

Request json

javascript
{
      url: '/Hello', 
      params: { name: 'test' }
}
  • GetTime

Request json

javascript
{
      url: '/GetTime', 
      params: { }
}

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C#dotnetdotnetcorefasthttpfasthttpapi

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言