@@ -4,10 +4,14 @@ layout: home
44
55hero :
66 name : " SimpleW"
7- text : " Web Server Library <br />.NET Core "
8- # tagline: Simple, Fast and Featured
7+ text : " Modern Web Server <br />for .NET"
8+ tagline : Designed for Simplicity. Built for Speed.
99 # tagline: Designed for Simplicity. Built for Speed. Packed with Power.
10- tagline : Powerfully Simple. Blazingly Fast.
10+ # tagline: Powerfully Simple. Seriously Fast.
11+ # tagline: Simple by Design. Fast and Powerful.
12+ # tagline: Simple. Fast. Powerful.
13+ # tagline: Simplicity First. Performance Built-In.
14+ # tagline: Simple by Design. Built for Speed.
1115 image :
1216 src : /logo-min.webp
1317 alt : SimpleW
@@ -24,17 +28,17 @@ hero:
2428
2529features :
2630 - icon : ⚡
27- title : Simple & Blazing Fast
31+ title : Zero Dependencies, Maximum Speed
2832 details : Built on top of native sockets. Minimal overhead, instant startup and high-performance workloads.
2933 - icon : 🌐
30- title : API REST
31- details : Define routes and controllers with automatic json serialization. Focus on your business logic .
32- - icon : 🔋
33- title : Built-in Features
34- details : Json Web Token, Cross-Origin Resource Sharing, SSL for security. Websockets and Server Sent Events for communication .
35- - icon : 🔬
36- title : Observability
37- details : Integrated OpenTelemetry with traces and metrics. Easier to monitor, debug, and analyze requests .
34+ title : Flexible Web Server
35+ details : Handle APIs, static files, and dynamic content through a simple routing model — with full control over behavior .
36+ - icon : 🛡️
37+ title : Production-Grade Core
38+ details : A fully integrated core designed for real-world usage covering security, communication, and observability without external dependencies .
39+ - icon : 🧩
40+ title : Powerful Addons
41+ details : Designed for extensibility. Integrate additional capabilities through independent modules without bloating your core .
3842
3943carousel :
4044 - src : /logo-min.webp
@@ -47,3 +51,150 @@ carousel:
4751 # - src: /simplewbot/simplew-frameworks-should-not-be-cages-min.jpg
4852
4953---
54+
55+ ## From Zero to Production
56+
57+ Start with a few lines of code, then add controllers, addons, and hosting features as your application grows.
58+
59+ ::: code-group
60+
61+ ``` csharp:line-numbers [Minimal]
62+ // debug log
63+ Log.SetSink(Log.ConsoleWriteLine, LogLevel.Debug);
64+
65+ // listen to all IPs port 8080
66+ var server = new SimpleWServer(IPAddress.Any, 8080);
67+
68+ // map handler to a route
69+ server.MapGet("/api/test/hello", () => {
70+ return new { message = "Hello World !" };
71+ });
72+
73+ // start a blocking background server
74+ await server.RunAsync();
75+ ```
76+
77+ ``` csharp:line-numbers [Controllers]
78+ class Program {
79+ static async Task Main() {
80+ // server
81+ await new SimpleWServer(IPAddress.Any, 8080)
82+ .MapControllers<Controller>("/api")
83+ .RunAsync();
84+ }
85+ }
86+
87+ public class TestController : Controller {
88+ // handler
89+ [Route("GET", "/test")]
90+ public object Hello(string name) {
91+ return new { message = $"{name}, Hello World !" };
92+ }
93+ }
94+ ```
95+
96+ ``` csharp:line-numbers [Production]
97+ class Program {
98+
99+ static async Task Main() {
100+
101+ var server = new SimpleWServer(IPAddress.Any, 8080);
102+
103+ // telemetry
104+ server.ConfigureTelemetry(options => {
105+ options.IncludeStackTrace = true;
106+ options.EnrichWithHttpSession = (activity, session) => {
107+ // override host with the X-Forwarded-Host header (set by a trusted reverse proxy)
108+ if (session.Request.Headers.TryGetValue("X-Forwarded-Host", out string? host) {
109+ activity.SetTag("url.host", host);
110+ }
111+ };
112+ });
113+
114+ // socket tuning
115+ server.Configure(options => {
116+ options.TcpNoDelay = true;
117+ options.ReuseAddress = true;
118+ options.TcpKeepAlive = true;
119+ });
120+
121+ // find all classes based on Controller class, and serve on the "/api" endpoint
122+ server.MapControllers<Controller>("/api");
123+
124+ // static files with cache
125+ server.UseStaticFilesModule(options => {
126+ options.Path = "/app/www/public";
127+ options.CacheTimeout = TimeSpan.FromDays(1);
128+ });
129+
130+ // Firewall
131+ server.UseFirewallModule(options => {
132+ options.AllowRules.Add(IpRule.Cidr("10.0.0.0/8"));
133+ options.AllowRules.Add(IpRule.Single("127.0.0.1"));
134+ options.MaxMindCountryDbPath = "/app/data/GeoLite2-Country.mmdb";
135+ options.AllowCountries.Add(CountryRule.Any("US"));
136+ });
137+
138+ // OpenID
139+ server.UseOpenIDModule(options => {
140+ options.Add("google", o => {
141+ o.Authority = "https://accounts.google.com";
142+ o.ClientId = "<google-client-id>";
143+ o.ClientSecret = "<google-client-secret>";
144+ o.PublicBaseUrl = "https://myapp.example.com";
145+ });
146+ });
147+
148+ // start a blocking background server
149+ await server.RunAsync();
150+ }
151+ }
152+
153+ public class TestController : Controller {
154+ // handler
155+ [Route("GET", "/test")]
156+ public object Hello(string name) {
157+ return new { message = $"{name}, Hello World !" };
158+ }
159+ }
160+ ```
161+
162+ ``` csharp:line-numbers [ASP.NET-like]
163+ var builder = SimpleWHost.CreateApplicationBuilder(args)
164+ .UseMicrosoftLogging();
165+
166+ builder.ConfigureSimpleW(server => {
167+ configureApp: server => {
168+ // razor
169+ server.UseRazorModule(options => {
170+ options.ViewsPath = "Views";
171+ });
172+ // OpenAPI JSON
173+ server.MapGet("/swagger.json", static (HttpSession session) => {
174+ return Swagger.Json(session);
175+ });
176+ // Swagger UI
177+ server.MapGet("/swagger", static (HttpSession session) => {
178+ return Swagger.UI(session);
179+ });
180+ // routes
181+ server.MapGet("/hello", () => {
182+ return new { mesage = "Hello World !" };
183+ });
184+ // ssl
185+ X509Certificate2 cert = new(@"C:\Users\SimpleW\ssl\domain.pfx", "password");
186+ var sslcontext = new SslContext(SslProtocols.Tls12 | SslProtocols.Tls13, cert, clientCertificateRequired: false, checkCertificateRevocation: false);
187+ server.UseHttps(sslcontext);
188+ },
189+ configureServer: options => {
190+ options.TcpNoDelay = true;
191+ options.ReuseAddress = true;
192+ options.TcpKeepAlive = true;
193+ }
194+ });
195+
196+ var host = builder.Build();
197+ await host.RunAsync();
198+ ```
199+
200+ :::
0 commit comments