.net Express is a minimal and flexible .NET 9 web application framework that provides a robust set of features for web and mobile applications.
- behaves like node.js Express
- fully written in .NET 9.0 C#
- fast
- use WebSockets and SSE over the same port
namespace dotNetExpress.examples;
internal partial class Examples
{
internal static async Task HelloWorld()
{
var app = new Express();
const int port = 8080;
app.Get("/", async Task (req, res, next) =>
{
await res.Send("Hello World");
});
await app.Listen(port, () =>
{
Console.WriteLine($"Example app listening on port {port}");
});
}
}
Demonstrates multiple routes, use of Params and Query
namespace dotNetExpress.examples;
internal partial class Examples
{
internal static async Task MultiRouter()
{
var app = new Express();
const int port = 8080;
var apiv1 = new Router();
var apiv2 = new Router();
app.Use("/api/v1", apiv1);
app.Use("/api/v2", apiv2);
apiv1.Get("/", async Task (req, res, next) =>
{
var serverId = req.Params["serverId"];
Console.WriteLine($"serverId {serverId}");
var sLimit = req.Query["limit"];
var sOffset = req.Query["offset"];
Console.WriteLine($"Pagination {sOffset} {sLimit}");
await res.Send("Hello World from api v1.");
});
apiv2.Get("/", async Task (req, res, next) =>
{
await res.Send("Hello World from api v2.");
});
app.Get("/", async Task (req, res, next) =>
{
await res.Send("Hello World from root route.");
});
await app.Listen(port, () =>
{
Console.WriteLine($"Example app listening on port {port}");
});
}
}
More examples in the Examples folder
For Multipart POST commands
- Multipart Parser from Http-Multipart-Data-Parser
- Microsoft.IO.RecyclableMemoryStream