forked from TechEmpower/FrameworkBenchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonModule.cs
More file actions
32 lines (27 loc) · 800 Bytes
/
JsonModule.cs
File metadata and controls
32 lines (27 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using Carter;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Utf8Json;
namespace Benchmarks
{
public class JsonModule : ICarterModule
{
private const int _bufferSize = 27;
public struct JsonMessage
{
public string message;
}
public void AddRoutes(IEndpointRouteBuilder app)
{
app.MapGet("/json", (HttpResponse res) =>
{
res.StatusCode = 200;
res.ContentType = "application/json";
res.ContentLength = _bufferSize;
var msg = new JsonMessage { message = "Hello, World!" };
return JsonSerializer.SerializeAsync(res.Body, msg);
});
}
}
}