How notesjor/tfres-tinyfastrestendpointserver works
Project Type & Purpose
• This is a C# library/framework (“TFRES–Tiny Fast REST Endpoint Server”) built on top of WatsonWebserver to let consumers quickly spin up async REST endpoints (and WebSockets).
• It isn’t a full-stack web application, but an embeddable HTTP server library with multi-target builds (NET Standard, .NET5/6/8).
File‐Structure Analysis
• Top‐level:
– TFRES.Core (core abstractions & shared logic)
– TFRES.DotNetStandard / .Net5 / .Net6 / .Net8 (platform-specific builds)
– TefresWebserver (the server runtime: Server.cs, EndpointManager, HttpContext/HttpRequest/HttpResponse, WebSocketHelper, OpenApiHelper, streaming support)
– Tests (a “TFRES.Test.SimpleServer” console app illustrating usage; also an HTML WebSocket demo)
• NuGet packaging: package.nuspec in TefresWebserver
• Configuration & metadata: .suo, .csproj, .xml docs, README, CHANGELOG, LICENSE, CONTRIBUTING, CODE_OF_CONDUCT
Key README Insights
• The Server class exposes AddEndpoint(HttpMethod, route, handler)
• Handlers receive an HttpContext, respond with Send(…) / SendFile(…) / WebSocketEasy()
• JSON serialization via Newtonsoft.Json is built-in
• Mono support & routing signatures changed from WatsonWebserver v2 → v3
Main Components
a. Client(s)
• HTTP clients (Postman, browser) or WebSocket clients (JS in browser, .NET clients)
b. TFRES Server Runtime (TefresWebserver Project)
• HTTP Listener (WatsonWebserver under the hood)
• EndpointManager (route → handler dispatch)
• HttpContext (wraps HttpRequest & HttpResponse)
• Handlers (user code registered via AddEndpoint)
• Serializer (Newtonsoft.Json)
• File/Chunk streaming (Chunk.cs)
• WebSocketHelper / EasyWebSocket
• OpenApiHelper (optional)
c. Library Modules
• TFRES.Core (shared interfaces, abstractions)
• TFRES.DotNetStandard / DotNet5 / DotNet6 / DotNet8 (assembly variations)
d. Example App (Tests/TFRES.Test.SimpleServer)
• References TFRES package, configures routes, hosts Server
Interactions & Data Flows
• Inside Handler: ctx.Request → business logic → ctx.Response.Send(…)
• For WebSocket: Initial HTTP “upgrade” request → WebSocketHelper creates EasyWebSocket → bidirectional message events
• For file streaming: Handler calls ctx.Response.SendFile → chunks via Chunk.cs
Architectural Patterns & Principles
• Modular multi-target library (Separation of Core vs Platform-specific)
• Pipeline dispatch (HTTP listener → routing → handler → response)
• Async/await throughout for non-blocking I/O
• Pluggable serialization (Newtonsoft.Json by default)
• Extension points via EndpointManager, OpenApiHelper, WebSocketHelper