All Projects → beetlex-io → Fasthttpapi

beetlex-io / Fasthttpapi

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

Projects that are alternatives of or similar to Fasthttpapi

GPONMonitor
GPON Monitoring tool for Dasan Networks GPON OLTs
Stars: ✭ 26 (-95.31%)
Mutual labels:  dotnetcore, webapi
Beast
HTTP and WebSocket built on Boost.Asio in C++11
Stars: ✭ 3,241 (+485.02%)
Mutual labels:  websocket, ssl
aspnet-core-web-api-using-odata
Demo application of my speech 'Add OData Support to Your Asp.Net Core Web Api' at Dotnet Konf İstanbul. http://dotnetkonf.com/
Stars: ✭ 28 (-94.95%)
Mutual labels:  dotnetcore, webapi
Dotnetlabs
.NET Labs -- Show Me the Tips and Tricks and Code
Stars: ✭ 135 (-75.63%)
Mutual labels:  webapi, dotnetcore
Cppserver
Ultra fast and low latency asynchronous socket server & client C++ library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and 10K connections problem solution
Stars: ✭ 528 (-4.69%)
Mutual labels:  websocket, ssl
Urf.core
Unit of Work & Repositories Framework - .NET Core, NET Standard, Entity Framework Core. 100% extensible & lightweight. Live demo: https://goo.gl/QpJVgd
Stars: ✭ 226 (-59.21%)
Mutual labels:  webapi, dotnetcore
Beef
Business Entity Execution Framework
Stars: ✭ 95 (-82.85%)
Mutual labels:  dotnetcore, webapi
Weapsy
ASP.NET Core CMS
Stars: ✭ 748 (+35.02%)
Mutual labels:  webapi, dotnetcore
Awesome Cms Core
Awesome CMS Core is an open source CMS built using ASP.Net Core & ReactJS with module seperation concern in mind and provide lastest trend of technology like .Net Core, React, Webpack, SASS, Background Job, Message Queue.
Stars: ✭ 352 (-36.46%)
Mutual labels:  webapi, dotnetcore
Ttyd
Share your terminal over the web
Stars: ✭ 4,030 (+627.44%)
Mutual labels:  websocket, ssl
Twig
Twig - less is more's web server for golang
Stars: ✭ 98 (-82.31%)
Mutual labels:  webapi, websocket
Telegraph
Secure Web Server for iOS, tvOS and macOS
Stars: ✭ 474 (-14.44%)
Mutual labels:  websocket, ssl
Event Sourcing Castanha
An Event Sourcing service template with DDD, TDD and SOLID. It has High Cohesion and Loose Coupling, it's a good start for your next Microservice application.
Stars: ✭ 68 (-87.73%)
Mutual labels:  webapi, dotnetcore
rabbitmq-labs
The source code for my RabbitMQ tutorials.
Stars: ✭ 45 (-91.88%)
Mutual labels:  dotnetcore, webapi
Furion
Make .NET development easier, more versatile, and more popular.
Stars: ✭ 902 (+62.82%)
Mutual labels:  webapi, dotnetcore
FSharpNetCoreWebApiTemplate
F# .net core web api template
Stars: ✭ 17 (-96.93%)
Mutual labels:  dotnetcore, webapi
Embedio
A tiny, cross-platform, module based web server for .NET
Stars: ✭ 1,007 (+81.77%)
Mutual labels:  websocket, dotnetcore
Asio2
Header only c++ network library, based on asio,support tcp,udp,http,websocket,rpc,ssl,icmp,serial_port.
Stars: ✭ 202 (-63.54%)
Mutual labels:  websocket, ssl
Microwebsrv2
The last Micro Web Server for IoTs (MicroPython) or large servers (CPython), that supports WebSockets, routes, template engine and with really optimized architecture (mem allocations, async I/Os). Ready for ESP32, STM32 on Pyboard, Pycom's chipsets (WiPy, LoPy, ...). Robust, efficient and documented!
Stars: ✭ 295 (-46.75%)
Mutual labels:  websocket, ssl
Echo
High performance, minimalist Go web framework
Stars: ✭ 21,297 (+3744.22%)
Mutual labels:  websocket, ssl

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 benchmarks-round20

Using

Install BeetleX.FastHttpApi

Install-Package BeetleX.FastHttpApi

Base sample code

    [Controller]
    class Program
    {
        private static BeetleX.FastHttpApi.HttpApiServer mApiServer;
        static void Main(string[] args)
        {
            mApiServer = new BeetleX.FastHttpApi.HttpApiServer();
            mApiServer.Options.LogLevel = BeetleX.EventArgs.LogType.Trace;
            mApiServer.Options.LogToConsole = true;
            mApiServer.Debug();//set view path with vs project folder
            mApiServer.Register(typeof(Program).Assembly);
            //mApiServer.Options.Port=80; set listen port to 80
            mApiServer.Open();//default listen port 9090  
            Console.Write(mApiServer.BaseServer);
            Console.Read();
        }
        // Get /hello?name=henry 
        // or
        // Get /hello/henry
        [Get(Route="{name}")]
        public object Hello(string name)
        {
            return $"hello {name} {DateTime.Now}";
        }
        // Get /GetTime  
        public object GetTime()
        {
            return DateTime.Now;
        }
    }

Hosting service

Install-Package BeetleX.FastHttpApi.Hosting -Version 0.8.2

     var builder = new HostBuilder()
     .ConfigureServices((hostContext, services) =>
      {
              services
               .AddSingleton<UserService>()
               .UseBeetlexHttp(o => {
                        o.Port = 8080;
                        o.LogToConsole = true;
                        o.LogLevel = BeetleX.EventArgs.LogType.Debug;
                        o.SetDebug();
               }, typeof(Program).Assembly);
        });
       builder.Build().Run();

Setting https

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

Defined result

  • Text result
    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);
        }
    }
  • Use result
        public object plaintext()
        {
            return new TextResult("Hello, World!");
        }

Cookies

        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

        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

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

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

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

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

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

or

        [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

        [Post]
        [FormUrlDataConvert]
        public object PostForm(string name, string value, IHttpContext context)
        {
            Console.WriteLine(context.Data);
            return $"{name}={value}";
        }
  • multipart/form-data
        [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
        [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
    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
        [CustomFilter]
        public string Hello(string name)
        {
            return DateTime.Now + " hello " + name;
        }

or

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

Parameters validation

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

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

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

Cross domain

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

Websocket

  • Server
[Controller]
    class Program
    {
        private static BeetleX.FastHttpApi.HttpApiServer mApiServer;
        static void Main(string[] args)
        {
            mApiServer = new BeetleX.FastHttpApi.HttpApiServer();
            mApiServer.Debug();
            mApiServer.Register(typeof(Program).Assembly);
            mApiServer.Open();
            Console.Write(mApiServer.BaseServer);
            Console.Read();
        }
        // Get /hello?name=henry 
        // or
        // Get /hello/henry
        [Get(R"{name}")]
        public object Hello(string name)
        {
            return $"hello {name} {DateTime.Now}";
        }
        // Get /GetTime  
        public object GetTime()
        {
            return DateTime.Now;
        }
    }
  • Hello

Request json

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

Request json

{
      url: '/GetTime', 
      params: { }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].