-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathllms.txt
More file actions
241 lines (186 loc) · 7.32 KB
/
llms.txt
File metadata and controls
241 lines (186 loc) · 7.32 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# Sisk Framework
> Sisk is a lightweight, agnostic, and robust .NET web development framework.
Sisk Framework is an open-source web server and development framework written in C# for .NET 6+. It provides a simple, explicit, and performant alternative to ASP.NET for building RESTful APIs, WebSocket servers, file servers, and more.
## Core Concepts
- **HttpServer**: The main server class that listens for HTTP requests
- **Router**: Routes incoming requests to handler methods
- **HttpRequest**: Represents an incoming HTTP request with headers, body, query, and route parameters
- **HttpResponse**: Represents an outgoing HTTP response with status, headers, and content
- **ListeningHost**: Configures host bindings and ports for the server
## Quick Start
```csharp
using Sisk.Core.Http;
using Sisk.Core.Routing;
var app = HttpServer.CreateBuilder()
.UseListeningPort(5000)
.Build();
app.Router.MapGet("/", request => new HttpResponse()
.WithContent("Hello, World!"));
app.Start();
```
## Routing
### Basic Routes
```csharp
router.MapGet("/users", GetUsers);
router.MapPost("/users", CreateUser);
router.MapGet("/users/<id>", GetUserById);
```
### Route Parameters
Route parameters use angle brackets `<paramName>`:
- `/users/<id>` - captures as `request.RouteParameters["id"]`
- `/files/<path:any>` - greedy match for path segments
### Request Handlers
Request handlers can be methods or lambdas that receive `HttpRequest` and return `HttpResponse`:
```csharp
static HttpResponse GetUsers(HttpRequest request)
{
return new HttpResponse()
.WithStatus(200)
.WithContent(JsonContent.Create(users));
}
```
## Request Handling
### Reading Request Data
```csharp
// Route parameters
string id = request.RouteParameters["id"].GetString();
// Query parameters
string? filter = request.Query["filter"].GetString();
// Headers
string? auth = request.Headers["Authorization"];
///// Body
// gets the request body as an string, using the request encoding as the encoder
string body = request.Body;
// or gets it in an byte array
byte[] bodyBytes = request.RawBody;
// or get from JSON
MyDto? dto = request.GetJsonContent<MyDto>();
// or else, you can stream it.
Stream requestStream = request.GetRequestStream();
// Form data
var form = request.GetFormContent();
```
### Response Building
```csharp
// Basic response
new HttpResponse(200);
// With content
new HttpResponse() {
Status = 200,
Content = new StringContent("text content"),
//Content = JsonContent.Create(obj),
//Content = new FileContent("file.pdf"),
//Content = new StreamContent(fileStream),
//Content = new HtmlContent(html),
Headers = new() {
Location = "https://example.com",
["X-Custom"] = "value"
}
}
```
## Middleware (Request Handlers)
Global request handlers execute before/after route handlers:
```csharp
router.GlobalRequestHandlers = new IRequestHandler[]
{
new AuthenticationHandler(),
new LoggingHandler()
};
```
Implement `IRequestHandler`:
```csharp
class AuthHandler : IRequestHandler
{
public RequestHandlerExecutionMode ExecutionMode
=> RequestHandlerExecutionMode.BeforeResponse;
public HttpResponse? Execute(HttpRequest request, HttpContext context)
{
if (!IsAuthenticated(request))
return new HttpResponse(401);
return null; // Continue to next handler
}
}
```
## WebSockets
```csharp
router.MapGet("/connect", async (HttpRequest req) =>
{
using var ws = await req.GetWebSocketAsync();
while (await ws.ReceiveMessageAsync(timeout: TimeSpan.FromSeconds(30)) is { } receivedMessage)
{
string msgText = receivedMessage.GetString();
Console.WriteLine("Received message: " + msgText);
await ws.SendAsync("Hello!");
}
return await ws.CloseAsync();
});
```
## Configuration
### Service Provider Pattern
```csharp
var app = HttpServer.CreateBuilder()
.UseListeningPort(5000)
.UseConfiguration(config =>
{
config.AccessLogsStream = LogStream.ConsoleOutput;
config.ThrowExceptions = true; // useful for debugging
})
.Build();
```
## Key Packages
- **Sisk.Core**: Core HTTP server and routing
- **Sisk.BasicAuth**: Basic authentication middleware
- **Sisk.SslProxy**: SSL/TLS proxy support
- **Sisk.Cadente**: Server-Sent Events (SSE) support
## Important Notes
- Sisk by default uses `HttpListener` internally (no Kestrel dependency)
- Works with .NET 6, 7, 8+ and Native AOT
- Cross-platform: Windows, Linux, macOS
- No additional SDK packages required beyond base .NET
- Thread-safe by default
- Explicit behavior - no magic or hidden conventions
## Documentation
### Getting Started
- Getting Started: https://docs.sisk-framework.org/docs/getting-started
- Installing: https://docs.sisk-framework.org/docs/installing
- Native AOT Support: https://docs.sisk-framework.org/docs/native-aot
- Deploying: https://docs.sisk-framework.org/docs/deploying
- Working with SSL: https://docs.sisk-framework.org/docs/ssl
- Cadente: https://docs.sisk-framework.org/docs/cadente
- Windows Setup: https://docs.sisk-framework.org/docs/registering-namespace
- FAQ: https://docs.sisk-framework.org/docs/faq
### Fundamentals
- Routing: https://docs.sisk-framework.org/docs/fundamentals/routing
- Request Handlers: https://docs.sisk-framework.org/docs/fundamentals/request-handlers
- Requests: https://docs.sisk-framework.org/docs/fundamentals/requests
- Responses: https://docs.sisk-framework.org/docs/fundamentals/responses
### Features
- Logging: https://docs.sisk-framework.org/docs/features/logging
- Server Sent Events: https://docs.sisk-framework.org/docs/features/server-sent-events
- Web Sockets: https://docs.sisk-framework.org/docs/features/websockets
- Discard Syntax: https://docs.sisk-framework.org/docs/features/discard-syntax
- Dependency Injection: https://docs.sisk-framework.org/docs/features/instancing
- Content Streaming: https://docs.sisk-framework.org/docs/features/content-streaming
- CORS: https://docs.sisk-framework.org/docs/features/cors
- File Server: https://docs.sisk-framework.org/docs/features/file-server
### Extensions
- Model Context Protocol (MCP): https://docs.sisk-framework.org/docs/extensions/mcp
- JSON-RPC: https://docs.sisk-framework.org/docs/extensions/json-rpc
- SSL Proxy: https://docs.sisk-framework.org/docs/extensions/ssl-proxy
- Basic Auth: https://docs.sisk-framework.org/docs/extensions/basic-auth
- Service Providers: https://docs.sisk-framework.org/docs/extensions/service-providers
- INI Configuration: https://docs.sisk-framework.org/docs/extensions/ini-configuration
- API Documentation: https://docs.sisk-framework.org/docs/extensions/api-documentation
### Advanced
- Manual Setup: https://docs.sisk-framework.org/docs/advanced/manual-setup
- Request Lifecycle: https://docs.sisk-framework.org/docs/advanced/request-lifecycle
- Forwarding Resolvers: https://docs.sisk-framework.org/docs/advanced/forwarding-resolvers
- HTTP Server Handlers: https://docs.sisk-framework.org/docs/advanced/http-server-handlers
- Multi-host Setup: https://docs.sisk-framework.org/docs/advanced/multi-host-setup
- HTTP Engines: https://docs.sisk-framework.org/docs/advanced/server-engines
### API Reference
- Full API Reference: https://docs.sisk-framework.org/api/
## Links
- Documentation: https://docs.sisk-framework.org/
- GitHub: https://github.com/sisk-http/core
- NuGet: https://www.nuget.org/packages/Sisk.HttpServer