Skip to content

Commit 401a830

Browse files
authored
Merge pull request #70 from MDA2AV/feature/add-fastendpoints
Add FastEndpoints framework
2 parents c2383bd + b3bb9c7 commit 401a830

7 files changed

Lines changed: 281 additions & 0 deletions

File tree

Http11Probe.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<Folder Name="/src/Servers/">
77
<Project Path="src/Servers/AspNetMinimal/AspNetMinimal.csproj" />
88
<Project Path="src/Servers/EmbedIOServer/EmbedIOServer.csproj" />
9+
<Project Path="src/Servers/FastEndpointsServer/FastEndpointsServer.csproj" />
910
<Project Path="src/Servers/GenHttpServer/GenHttpServer.csproj" />
1011
<Project Path="src/Servers/GlyphServer/GlyphServer.csproj" />
1112
<Project Path="src/Servers/NetCoreServerFramework/NetCoreServerFramework.csproj" />
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
---
2+
title: "FastEndpoints"
3+
toc: false
4+
breadcrumbs: false
5+
---
6+
7+
**Language:** C# · [View source on GitHub](https://github.com/MDA2AV/Http11Probe/tree/main/src/Servers/FastEndpointsServer)
8+
9+
## Dockerfile
10+
11+
```dockerfile
12+
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
13+
WORKDIR /src
14+
COPY Directory.Build.props .
15+
COPY src/Servers/FastEndpointsServer/ src/Servers/FastEndpointsServer/
16+
RUN dotnet restore src/Servers/FastEndpointsServer/FastEndpointsServer.csproj
17+
RUN dotnet publish src/Servers/FastEndpointsServer/FastEndpointsServer.csproj -c Release -o /app --no-restore
18+
19+
FROM mcr.microsoft.com/dotnet/aspnet:10.0
20+
WORKDIR /app
21+
COPY --from=build /app .
22+
ENTRYPOINT ["dotnet", "FastEndpointsServer.dll"]
23+
```
24+
25+
## Source — `Program.cs`
26+
27+
```csharp
28+
using FastEndpoints;
29+
30+
var builder = WebApplication.CreateBuilder(args);
31+
32+
builder.WebHost.UseUrls("http://+:8080");
33+
builder.Services.AddFastEndpoints(o => o.Assemblies = [typeof(GetRoot).Assembly]);
34+
35+
var app = builder.Build();
36+
37+
app.UseFastEndpoints();
38+
39+
app.Run();
40+
41+
// ── GET / ──────────────────────────────────────────────────────
42+
43+
sealed class GetRoot : EndpointWithoutRequest
44+
{
45+
public override void Configure()
46+
{
47+
Get("/");
48+
AllowAnonymous();
49+
}
50+
51+
public override async Task HandleAsync(CancellationToken ct)
52+
{
53+
await HttpContext.Response.WriteAsync("OK", ct);
54+
}
55+
}
56+
57+
// ── HEAD / ─────────────────────────────────────────────────────
58+
59+
sealed class HeadRoot : EndpointWithoutRequest
60+
{
61+
public override void Configure()
62+
{
63+
Verbs("HEAD");
64+
Routes("/");
65+
AllowAnonymous();
66+
}
67+
68+
public override async Task HandleAsync(CancellationToken ct)
69+
{
70+
HttpContext.Response.StatusCode = 200;
71+
await HttpContext.Response.WriteAsync("", ct);
72+
}
73+
}
74+
75+
// ── POST / ─────────────────────────────────────────────────────
76+
77+
sealed class PostRoot : EndpointWithoutRequest
78+
{
79+
public override void Configure()
80+
{
81+
Post("/");
82+
AllowAnonymous();
83+
}
84+
85+
public override async Task HandleAsync(CancellationToken ct)
86+
{
87+
using var reader = new StreamReader(HttpContext.Request.Body);
88+
var body = await reader.ReadToEndAsync(ct);
89+
await HttpContext.Response.WriteAsync(body, ct);
90+
}
91+
}
92+
93+
// ── OPTIONS / ──────────────────────────────────────────────────
94+
95+
sealed class OptionsRoot : EndpointWithoutRequest
96+
{
97+
public override void Configure()
98+
{
99+
Verbs("OPTIONS");
100+
Routes("/");
101+
AllowAnonymous();
102+
}
103+
104+
public override async Task HandleAsync(CancellationToken ct)
105+
{
106+
HttpContext.Response.Headers["Allow"] = "GET, HEAD, POST, OPTIONS";
107+
HttpContext.Response.StatusCode = 200;
108+
await HttpContext.Response.WriteAsync("", ct);
109+
}
110+
}
111+
112+
// ── POST /echo ─────────────────────────────────────────────────
113+
114+
sealed class PostEcho : EndpointWithoutRequest
115+
{
116+
public override void Configure()
117+
{
118+
Post("/echo");
119+
AllowAnonymous();
120+
}
121+
122+
public override async Task HandleAsync(CancellationToken ct)
123+
{
124+
var sb = new System.Text.StringBuilder();
125+
foreach (var h in HttpContext.Request.Headers)
126+
foreach (var v in h.Value)
127+
sb.AppendLine($"{h.Key}: {v}");
128+
await HttpContext.Response.WriteAsync(sb.ToString(), ct);
129+
}
130+
}
131+
```
132+
133+
## Source — `FastEndpointsServer.csproj`
134+
135+
```xml
136+
<Project Sdk="Microsoft.NET.Sdk.Web">
137+
138+
<PropertyGroup>
139+
<TargetFramework>net10.0</TargetFramework>
140+
<Nullable>enable</Nullable>
141+
<ImplicitUsings>enable</ImplicitUsings>
142+
<IsPackable>false</IsPackable>
143+
</PropertyGroup>
144+
145+
<ItemGroup>
146+
<PackageReference Include="FastEndpoints" Version="7.2.0" />
147+
</ItemGroup>
148+
149+
</Project>
150+
```

docs/static/probe/render.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ window.ProbeRender = (function () {
408408
'EmbedIO': '/Http11Probe/servers/embedio/',
409409
'Envoy': '/Http11Probe/servers/envoy/',
410410
'Express': '/Http11Probe/servers/express/',
411+
'FastEndpoints': '/Http11Probe/servers/fastendpoints/',
411412
'FastHTTP': '/Http11Probe/servers/fasthttp/',
412413
'Flask': '/Http11Probe/servers/flask/',
413414
'GenHTTP': '/Http11Probe/servers/genhttp/',
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
2+
WORKDIR /src
3+
COPY Directory.Build.props .
4+
COPY src/Servers/FastEndpointsServer/ src/Servers/FastEndpointsServer/
5+
RUN dotnet restore src/Servers/FastEndpointsServer/FastEndpointsServer.csproj
6+
RUN dotnet publish src/Servers/FastEndpointsServer/FastEndpointsServer.csproj -c Release -o /app --no-restore
7+
8+
FROM mcr.microsoft.com/dotnet/aspnet:10.0
9+
WORKDIR /app
10+
COPY --from=build /app .
11+
ENTRYPOINT ["dotnet", "FastEndpointsServer.dll"]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="FastEndpoints" Version="7.2.0" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using FastEndpoints;
2+
3+
var builder = WebApplication.CreateBuilder(args);
4+
5+
builder.WebHost.UseUrls("http://+:8080");
6+
builder.Services.AddFastEndpoints(o => o.Assemblies = [typeof(GetRoot).Assembly]);
7+
8+
var app = builder.Build();
9+
10+
app.UseFastEndpoints();
11+
12+
app.Run();
13+
14+
// ── GET / ──────────────────────────────────────────────────────
15+
16+
sealed class GetRoot : EndpointWithoutRequest
17+
{
18+
public override void Configure()
19+
{
20+
Get("/");
21+
AllowAnonymous();
22+
}
23+
24+
public override async Task HandleAsync(CancellationToken ct)
25+
{
26+
await HttpContext.Response.WriteAsync("OK", ct);
27+
}
28+
}
29+
30+
// ── HEAD / ─────────────────────────────────────────────────────
31+
32+
sealed class HeadRoot : EndpointWithoutRequest
33+
{
34+
public override void Configure()
35+
{
36+
Verbs("HEAD");
37+
Routes("/");
38+
AllowAnonymous();
39+
}
40+
41+
public override async Task HandleAsync(CancellationToken ct)
42+
{
43+
HttpContext.Response.StatusCode = 200;
44+
await HttpContext.Response.WriteAsync("", ct);
45+
}
46+
}
47+
48+
// ── POST / ─────────────────────────────────────────────────────
49+
50+
sealed class PostRoot : EndpointWithoutRequest
51+
{
52+
public override void Configure()
53+
{
54+
Post("/");
55+
AllowAnonymous();
56+
}
57+
58+
public override async Task HandleAsync(CancellationToken ct)
59+
{
60+
using var reader = new StreamReader(HttpContext.Request.Body);
61+
var body = await reader.ReadToEndAsync(ct);
62+
await HttpContext.Response.WriteAsync(body, ct);
63+
}
64+
}
65+
66+
// ── OPTIONS / ──────────────────────────────────────────────────
67+
68+
sealed class OptionsRoot : EndpointWithoutRequest
69+
{
70+
public override void Configure()
71+
{
72+
Verbs("OPTIONS");
73+
Routes("/");
74+
AllowAnonymous();
75+
}
76+
77+
public override async Task HandleAsync(CancellationToken ct)
78+
{
79+
HttpContext.Response.Headers["Allow"] = "GET, HEAD, POST, OPTIONS";
80+
HttpContext.Response.StatusCode = 200;
81+
await HttpContext.Response.WriteAsync("", ct);
82+
}
83+
}
84+
85+
// ── POST /echo ─────────────────────────────────────────────────
86+
87+
sealed class PostEcho : EndpointWithoutRequest
88+
{
89+
public override void Configure()
90+
{
91+
Post("/echo");
92+
AllowAnonymous();
93+
}
94+
95+
public override async Task HandleAsync(CancellationToken ct)
96+
{
97+
var sb = new System.Text.StringBuilder();
98+
foreach (var h in HttpContext.Request.Headers)
99+
foreach (var v in h.Value)
100+
sb.AppendLine($"{h.Key}: {v}");
101+
await HttpContext.Response.WriteAsync(sb.ToString(), ct);
102+
}
103+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name": "FastEndpoints", "language": "C#"}

0 commit comments

Comments
 (0)