### Full API Documentation Setup Example Source: https://github.com/sisk-http/docs/blob/master/_site/docs/extensions/api-documentation.html This comprehensive example demonstrates how to configure the `HttpServer` to include API documentation generation. It shows the use of `UseApiDocumentation` with custom application details and an `OpenApiExporter`, alongside routing setup. ```csharp using Sisk.Core.Entity; using Sisk.Core.Http; using Sisk.Core.Routing; using Sisk.Documenting; using Sisk.Documenting.Annotations; using var host = HttpServer.CreateBuilder(5555) .UseCors(CrossOriginResourceSharingHeaders.CreatePublicContext()) .UseApiDocumentation( context: new ApiGenerationContext() { ApplicationName = "My application", ApplicationDescription = "It greets someone." }, routerPath: "/api/docs", exporter: new OpenApiExporter() { ServerUrls = ["http://localhost:5555/"] }) .UseRouter(router => { router.SetObject(new MyController()); }) .Build(); await host.StartAsync(); class MyController { [RouteGet] [ApiEndpoint(Description = "Returns a greeting message.")] [ApiQueryParameter(name: "name", IsRequired = false, Description = "The name of the person to greet.", Type = "string")] public HttpResponse Index(HttpRequest request) { string? name = request.Query["name"].MaybeNullOrEmpty() ?? "world"; return new HttpResponse($"Hello, {name}!"); } } ``` -------------------------------- ### Basic Authentication Setup Source: https://github.com/sisk-http/docs/blob/master/_site/docs/extensions/basic-auth.html Example of setting up basic authentication with a username and password. ```go package main import ( "fmt" "net/http" "strings" ) func main() { http.HandleFunc("/protected", basicAuth(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Welcome to the protected area!") })) fmt.Println("Server starting on :8080...") http.ListenAndServe(":8080", nil) } func basicAuth(handler http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { user, pass, ok := r.BasicAuth() if !ok || user != "testuser" || pass != "testpass" { w.Header().Set("WWW-Authenticate", "Basic realm=\"Restricted\"") http.Error(w, "Unauthorized", http.StatusUnauthorized) return } handler(w, r) } } ``` -------------------------------- ### Example Property Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Documenting.ApiEndpointRequestExample.Example.html Gets the actual example request content. ```APIDOC ## Example Property ### Description Gets the actual example request content. ### Signature ```csharp public string? Example { get; } ``` ``` -------------------------------- ### Example Property Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Documenting.ApiEndpointResponse.Example.html Gets the example response content. ```APIDOC ## Property Example ### Description Gets the example response content. ### Signature ```csharp public string? Example { get; } ``` ``` -------------------------------- ### Basic Authentication Setup Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.BasicAuth.html Example of how to set up basic authentication using Sisk.BasicAuth. This typically involves providing a username and password. ```javascript const auth = new Sisk.BasicAuth("user", "password"); ``` -------------------------------- ### Basic HTTP Server Setup with Custom Handler Source: https://github.com/sisk-http/docs/blob/master/_site/docs/features/logging.html Set up an HTTP server with a custom message handler to process requests and responses. This example demonstrates basic server creation and routing. ```C# var app = HttpServer.CreateBuilder(host => { host.UseListeningPort(5555); host.UseHandler(); }); app.Router += new Route(RouteMethod.Any, "/json", request => { return new HttpResponse() .WithContent(JsonContent.Create(new { method = request.Method.Method, path = request.Path, specialMessage = "Hello, world!!" })); }); await app.StartAsync(); ``` -------------------------------- ### Start() Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.HttpServer.Start.html Starts listening to the set port and handling requests on this server. ```APIDOC ## Start() ### Description Starts listening to the set port and handling requests on this server. ### Method void ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Build a Basic HTTP Server with Sisk Source: https://github.com/sisk-http/docs/blob/master/_site/docs/getting-started.html Instantiate and configure an HTTP server using the Sisk builder pattern. This example sets up a server to listen on port 5000 and maps a GET request for the root path to return 'Hello, world!'. ```csharp class Program { static async Task Main(string[] args) { using var app = HttpServer.CreateBuilder() .UseListeningPort("http://localhost:5000/") .Build(); app.Router.MapGet("/", request => { return new HttpResponse() { Status = 200, Content = new StringContent("Hello, world!") }; }); await app.StartAsync(); } } ``` -------------------------------- ### Start() Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Ssl.SslProxy.Start.html Starts the SslProxy and begins routing traffic to the configured remote endpoint. ```APIDOC ## Start() ### Description Starts the [SslProxy](Sisk.Ssl.SslProxy.html) and start routing traffic to the set remote endpoint. ### Method public void Start() ``` -------------------------------- ### Configure and Start HTTP Server Source: https://github.com/sisk-http/docs/blob/master/docs/advanced/manual-setup.md Initializes the HTTP server configuration, adds the `ListeningHost`, creates the `HttpServer` instance, and starts the server. ```csharp HttpServerConfiguration config = new HttpServerConfiguration(); config.ListeningHosts.Add(myHost); // Add our ListeningHost to this server configuration HttpServer server = new HttpServer(config); server.Start(); // Starts the server Console.ReadKey(); // Prevents the application from exiting ``` -------------------------------- ### Setup() Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.CompressedContent.Setup.html Represents the method that is invoked once within the constructor to setup this compressor. This method is indeeded to add the missing Content-Encoding headers used by this compressor. ```APIDOC ## Setup() ### Description Represents the method that is invoked once within the constructor to setup this compressor. This method is indeeded to add the missing Content-Encoding headers used by this compressor. ### Method abstract void ### Parameters This method does not take any parameters. ### Returns This method does not return a value. ``` -------------------------------- ### Set Up HTTP Server Configuration and Start Source: https://github.com/sisk-http/docs/blob/master/_site/docs/advanced/manual-setup.html Initialize an HttpServerConfiguration, add the configured ListeningHost to it, create an HttpServer instance with the configuration, and start the server. This is the final step to make the server operational. ```csharp HttpServerConfiguration config = new HttpServerConfiguration(); config.ListeningHosts.Add(myHost); // Add our ListeningHost to this server configuration HttpServer server = new HttpServer(config); server.Start(); // Starts the server Console.ReadKey(); // Prevents the application from exiting ``` -------------------------------- ### HttpHostHandler Constructor Example Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Cadente.HttpHostHandler.-ctor.html Demonstrates the initialization of the HttpHostHandler. This is a basic setup for handling HTTP requests. ```csharp var handler = new HttpHostHandler(); ``` -------------------------------- ### Start() Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Cadente.HttpHost.Start.html Starts the HTTP host and begins listening for incoming connections. This is a void method and does not return any value. ```APIDOC ## Start() ### Description Starts the HTTP host and begins listening for incoming connections. ### Method void ### Signature public void Start() ``` -------------------------------- ### Start() Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.Streams.HttpStreamPingPolicy.Start.html Starts sending periodic pings to the client. This overload uses default configurations. ```APIDOC ## Start() ### Description Starts sending periodic pings to the client. ### Method public void Start() ### Parameters None ### Response None ``` -------------------------------- ### Middleware Example Source: https://github.com/sisk-http/docs/blob/master/_site/docs/fundamentals/requests.html An example of how to implement and use middleware for tasks like logging or authentication before a request handler is executed. ```go func loggerMiddleware(next sisk.HandlerFunc) sisk.HandlerFunc { return func(ctx *sisk.Ctx) error { fmt.Printf("Request received: %s %s\n", ctx.Method(), ctx.Path()) return next(ctx) } } app.Use(loggerMiddleware) ``` -------------------------------- ### Start HTTP Server Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.HttpServer.Start.html This snippet demonstrates how to start an HTTP server using Sisk.Core.Http.HttpServer.Start(). It requires setting up routes and specifying the port to listen on. ```csharp await new HttpServer(new Routes( new Route("GET", "/", (ctx, next) => ctx.Response.SendFileAsync("index.html")), new Route("GET", "/about", (ctx, next) => ctx.Response.SendTextAsync("About Us")) )).StartAsync(8080); Console.WriteLine("Server started on port 8080"); await Task.Delay(-1); ``` -------------------------------- ### Abstract Setup Method Signature Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.CompressedContent.Setup.html This is the abstract method signature for Setup(). Subclasses must implement this method to add necessary Content-Encoding headers. ```csharp public abstract void Setup() ``` -------------------------------- ### Start Method Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Ssl.SslProxy.Start.html Information about the Start method in the Sisk.Ssl.SslProxy namespace. ```APIDOC ## Method Start Namespace [Sisk](Sisk.html).[Ssl](Sisk.Ssl.html) Assembly Sisk.SslProxy.dll ``` -------------------------------- ### Basic Route Definition Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Routing.RouteAttribute.html Example of defining a GET route for the '/users' path. ```csharp [HttpGet("/users")] public IActionResult GetUsers() { ... } ``` -------------------------------- ### Start(bool, bool) Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.Hosting.HttpServerHostContext.Start.html Starts the HTTP server. This method allows for configuration of verbosity and whether the server should prevent halting. ```APIDOC ## Start(bool, bool) ### Description Starts the HTTP server. This method allows for configuration of verbosity and whether the server should prevent halting. ### Method Signature ```csharp public void Start(bool verbose = true, bool preventHault = true) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response None (void return type) #### Response Example None ``` -------------------------------- ### Start and Check Service Status Source: https://github.com/sisk-http/docs/blob/master/docs/deploying.md Start your newly created service and verify its running status. Look for 'Active: active' to confirm it's running correctly. ```sh $ sudo systemctl start my-app $ sudo systemctl status my-app ``` -------------------------------- ### Enable Service to Start on Boot Source: https://github.com/sisk-http/docs/blob/master/docs/deploying.md Enable your service to automatically start every time the system boots up. ```sh $ sudo systemctl enable my-app ``` -------------------------------- ### Configure Method Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.RotatingLogPolicy.Configure.html Defines the time interval and size threshold for starting the task, and then starts the task. ```APIDOC ## Configure(long, TimeSpan, RotatingLogPolicyCompressor?) ### Description Defines the time interval and size threshold for starting the task, and then starts the task. ### Method Signature public void Configure(long maximumSize, TimeSpan due, RotatingLogPolicyCompressor? compressor = null) ### Parameters #### Parameters - **maximumSize** (long) - Required - The non-negative size threshold of the log file size in byte count. - **due** (TimeSpan) - Required - The time interval between checks. - **compressor** (RotatingLogPolicyCompressor) - Optional - The optional compressor to use for log file compression. If null, the default compressor (GZip) will be used. ``` -------------------------------- ### Install Sisk.IniConfiguration.Core Package Source: https://github.com/sisk-http/docs/blob/master/_site/docs/extensions/ini-configuration.html Install the core package if you only need INI serializers without Sisk framework dependencies. ```bash $ dotnet add package Sisk.IniConfiguration.Core ``` -------------------------------- ### C# Example: ApiEndpointResponse with Example Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Documenting.ApiEndpointResponse.html Illustrates how to provide an example of a response body. ```csharp var response = new ApiEndpointResponse( "Not Found", "The requested resource could not be found.", "404 Not Found", new Dictionary { { "Content-Type", "application/json" } }, new Dictionary { { "X-Request-ID", "ghi-789" } }, null, @"{ \"error\": \"Resource not found\" }" ); ``` -------------------------------- ### Controller with RoutePost Example Source: https://github.com/sisk-http/docs/blob/master/docs/fundamentals/routing.md An example of a UsersController inheriting from ControllerBase, demonstrating a POST route to create a user and access request data. ```C# [RoutePrefix("/api/users")] public class UsersController : ControllerBase { [RoutePost] public async Task Create() { // reads the JSON data from the current request UserCreationDto? user = JsonSerializer.DeserializeAsync(Request.Body); ... Database.Users.Add(user); return new HttpResponse(201); } } ``` -------------------------------- ### Configure JSON-RPC API with Sisk Source: https://github.com/sisk-http/docs/blob/master/docs/extensions/json-rpc.md Set up a Sisk HTTP server to handle JSON-RPC requests. This example maps methods from a MathOperations class and configures routes for HTTP POST, GET, and WebSockets. ```csharp using var app = HttpServer.CreateBuilder(port: 5555) .UseJsonRPC((sender, args) => { // add all methods tagged with WebMethod to the JSON-RPC handler args.Handler.Methods.AddMethodsFromType(new MathOperations()); // maps the /service route to handle JSON-RPC POST and GET requests args.Router.MapPost("/service", args.Handler.Transport.HttpPost); args.Router.MapGet("/service", args.Handler.Transport.HttpGet); // creates an websocket handler on GET /ws args.Router.MapGet("/ws", request => { var ws = request.GetWebSocket(); ws.OnReceive += args.Handler.Transport.WebSocket; ws.WaitForClose(timeout: TimeSpan.FromSeconds(30)); return ws.Close(); }); }) .Build(); await app.StartAsync(); ``` -------------------------------- ### Basic Route Definition in Sisk Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Routing.RouterModule.html Defines a simple GET route for the root path '/'. This is a fundamental example for starting with Sisk routing. ```csharp using Sisk.Core.Routing; var router = new Router(); router.Get("/", (req, res) => { res.Text("Hello World!"); }); ``` -------------------------------- ### Start(string, TimeSpan) Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.Streams.HttpStreamPingPolicy.Start.html Configures and starts sending periodic pings to the client with a specified data message and interval. ```APIDOC ## Start(string, TimeSpan) ### Description Configures and starts sending periodic pings to the client. ### Method public void Start(string dataMessage, TimeSpan interval) ### Parameters #### Path Parameters * **dataMessage** (string) - Required - The message to send with each ping. * **interval** (TimeSpan) - Required - The time interval between pings. ``` -------------------------------- ### C# Example Property Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Documenting.ApiEndpointRequestExample.Example.html Represents the Example property within the Sisk.Documenting.ApiEndpointRequestExample class. It is used to get the actual example request content. ```csharp public string? Example { get; } ``` -------------------------------- ### C# ApiResponseAttribute Example Property Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Documenting.Annotations.ApiResponseAttribute.Example.html Gets or sets the example response content for an API response attribute. ```csharp public string? Example { get; set; } ``` -------------------------------- ### Flush() Example Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.LogStream.Flush.html This example demonstrates the usage of the Flush() method. It ensures that any pending log entries are immediately written to the output stream. ```csharp if (!article) return; if (typeof TurndownService === 'undefined') { const script = document.createElement('script'); script.src = 'https://unpkg.com/turndown/dist/turndown.js'; script.onload = function() { convertAndCopy(article); }; document.head.appendChild(script); } else { convertAndCopy(article); } copyDropdown.classList.remove('show'); }); function convertAndCopy(article) { const turndown = new TurndownService({ headingStyle: 'atx', codeBlockStyle: 'fenced' }); turndown.addRule('codeBlocks', { filter: ['pre'] , replacement: function(content, node) { const code = node.querySelector('code'); const langClass = code?.className.match(/lang-(\w+)/); const lang = langClass ? langClass[1] : ''; const text = code?.textContent || content; return '\n\n```' + lang + '\n' + text.trim() + '\n```\n\n'; } }); const markdown = turndown.turndown(article.innerHTML); navigator.clipboard.writeText(markdown); } })(); ``` -------------------------------- ### Description Property Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Documenting.ApiEndpointRequestExample.Description.html Gets the description of the request example. ```APIDOC ### Description Gets the description of the request example. ```csharp public string Description { get; } ``` ``` -------------------------------- ### Setup Method Signature Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.DeflateContent.Setup.html The public override signature for the Setup method. This method is intended for internal use within the constructor to configure the compressor and add necessary Content-Encoding headers. ```csharp public override void Setup() ``` -------------------------------- ### Install Dependencies and Build Documentation Source: https://github.com/sisk-http/docs/blob/master/_site/readme.html This shell script demonstrates the commands to install project dependencies using Bun and perform a full documentation build, including cleaning, translation, and packaging. ```shell # Restore package bun install # Full build (clean, translate, build) bun pack ``` -------------------------------- ### Get Body Contents Example Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.HttpRequest.GetBodyContents.html Demonstrates how to get the body contents of an HttpRequest. This method is useful for accessing raw request data. ```csharp public static async Task GetBodyContents(this HttpRequest request) { using var reader = new StreamReader(request.Body, Encoding.UTF8, true, 1024, false); return await reader.ReadToEndAsync(); } ``` -------------------------------- ### Example INI File Structure Source: https://github.com/sisk-http/docs/blob/master/_site/docs/extensions/ini-configuration.html This is an example of an 'app.ini' file structure that can be used with Sisk.IniConfiguration. It includes server settings, CORS policies, and custom parameters. ```ini [Server] # Multiple listen addresses are supported Listen = http://localhost:5552/ Listen = http://localhost:5553/ ThrowExceptions = false AccessLogsStream = console [Cors] AllowMethods = GET, POST AllowHeaders = Content-Type, Authorization AllowOrigin = * [Parameters] Name = "Kanye West" ``` -------------------------------- ### ApiResponseAttribute.Example Property Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Documenting.Annotations.ApiResponseAttribute.Example.html Gets or sets the example response content for an API response. ```APIDOC ## Property Example ### Description Gets or sets the example response content. ### Property Signature ```csharp public string? Example { get; set; } ``` ``` -------------------------------- ### ExampleLanguage Property Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Documenting.Annotations.ApiRequestAttribute.ExampleLanguage.html Gets or sets the programming language used in the example, if applicable. ```APIDOC ## ExampleLanguage ### Description Gets or sets the programming language used in the example, if applicable. ### Signature ```csharp public string? ExampleLanguage { get; set; } ``` ``` -------------------------------- ### Route with Parameter Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Routing.RouteAttribute.html Example of defining a GET route with a user ID parameter. ```csharp [HttpGet("/users/{id}")] public IActionResult GetUserById(int id) { ... } ``` -------------------------------- ### Create and Start Sisk HTTP Server Source: https://github.com/sisk-http/docs/blob/master/_site/llms.txt This snippet demonstrates how to create a basic Sisk HTTP server, configure the listening port, and start the server. It also includes a simple route for the root path. ```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(); ``` -------------------------------- ### Basic GET Route Mapping in Sisk Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Routing.Router.MapGet.html Defines a simple GET route that responds with 'Hello, World!' to requests at the root path. This is a fundamental example for setting up basic routing. ```csharp Router.MapGet("/", () => "Hello, World!"); ``` -------------------------------- ### ExampleLanguage Property Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Documenting.Annotations.ApiResponseAttribute.ExampleLanguage.html Gets or sets the programming language used in the example, if applicable. This property is part of the ApiResponseAttribute and helps in specifying the language for code examples within API documentation. ```APIDOC ## Property ExampleLanguage ### Description Gets or sets the programming language used in the example, if applicable. ### Signature ```csharp public string? ExampleLanguage { get; set; } ``` ``` -------------------------------- ### ApiRequestAttribute.Example Property Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Documenting.Annotations.ApiRequestAttribute.Example.html Gets or sets the actual example request content for an API request. ```APIDOC ## Property Example ### Description Gets or sets the actual example request content. ### Property Signature ```csharp public string? Example { get; set; } ``` ``` -------------------------------- ### Basic INI Configuration Example Source: https://github.com/sisk-http/docs/blob/master/_site/docs/extensions/ini-configuration.html Demonstrates how to load and access configuration values from an INI file. Ensure the INI file is correctly formatted and accessible. ```python from sisk.config import IniConfig # Assuming 'config.ini' is in the same directory or a specified path config = IniConfig('config.ini') # Accessing values username = config.get('database', 'user') password = config.get('database', 'password') host = config.get('server', 'host', 'localhost') print(f"Username: {username}") print(f"Password: {password}") print(f"Host: {host}") ``` -------------------------------- ### StartServer Method Implementation Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.Engine.HttpListenerAbstractEngine.StartServer.html This snippet shows the core logic for starting the HTTP server. It involves creating and appending a script tag for Turndown if it's not already defined, and then proceeds to convert and copy the article content. ```javascript if (typeof TurndownService === 'undefined') { const script = document.createElement('script'); script.src = 'https://unpkg.com/turndown/dist/turndown.js'; script.onload = function() { convertAndCopy(article); }; document.head.appendChild(script); } else { convertAndCopy(article); } copyDropdown.classList.remove('show'); ``` -------------------------------- ### Route with Multiple Methods Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Routing.RouteAttribute.html Example of defining a route that accepts both GET and POST requests. ```csharp [HttpMethods("GET", "POST")] [Route("/items")] public IActionResult HandleItems() { ... } ``` -------------------------------- ### Example HTTP Request with Origin Header Source: https://github.com/sisk-http/docs/blob/master/docs/features/cors.md A sample HTTP GET request demonstrating the inclusion of the Origin header. ```http GET /api/users HTTP/1.1 Host: example.com Origin: http://example.com ... ``` -------------------------------- ### Initialize IniConfiguration Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.IniConfiguration.html Demonstrates how to create a new instance of IniConfiguration, optionally loading from a file path. ```csharp var config = new IniConfiguration("path/to/your/config.ini"); // Or create an empty configuration // var config = new IniConfiguration(); ``` -------------------------------- ### FormatEndpointRequestExamples Property Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Documenting.Html.HtmlDocumentationExporter.FormatEndpointRequestExamples.html Gets or sets the format string used for endpoint request examples within the HTML documentation. ```APIDOC ## FormatEndpointRequestExamples ### Description Gets or sets the format string for endpoint request examples. ### Property `public string FormatEndpointRequestExamples { get; set; }` ``` -------------------------------- ### GET Route with Multiple Parameters in Sisk Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Routing.Router.MapGet.html Illustrates mapping a GET route that accepts two parameters, 'name' and 'city'. The route returns a combined greeting. This example highlights handling multiple dynamic segments in a URL. ```csharp Router.MapGet("/hello/{name}/{city}", (string name, string city) => $"Hello, {name} from {city}!"); ``` -------------------------------- ### UseBootstraper with Synchronous Action Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.Hosting.HttpServerHostContextBuilder.UseBootstraper.html Adds a synchronous action to be executed before the HTTP server starts. This is useful for one-time setup tasks. ```csharp public HttpServerHostContextBuilder UseBootstraper(Action bootstrapAction) ``` -------------------------------- ### Example Prefix Configuration Source: https://github.com/sisk-http/docs/blob/master/_site/docs/registering-namespace.html This example demonstrates how to set the `PREFIX` variable in the batch script to listen on a custom host and path. The format must include the URL scheme, host, port, and a trailing slash. ```batch SET PREFIX=http://my-application.example.test/ ``` -------------------------------- ### ExampleLanguage Property Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Documenting.ApiEndpointRequestExample.ExampleLanguage.html Gets the programming language used in the example, if applicable. This property is part of the Sisk.Documenting namespace and is available in the Sisk.Documenting.dll assembly. ```APIDOC ### Property ExampleLanguage Gets the programming language used in the example, if applicable. ```csharp public string? ExampleLanguage { get; } ``` ``` -------------------------------- ### UseBootstraper Method Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.Hosting.HttpServerHostContextBuilder.UseBootstraper.html Configures the HTTP server host context builder with a bootstraper. ```APIDOC ## HttpServerHostContextBuilder.UseBootstraper ### Description This method configures the `HttpServerHostContextBuilder` by providing a bootstraper function. The bootstraper is executed during the host's startup process. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters This method does not take any explicit parameters in the provided documentation, but it is expected to be used in a fluent builder pattern. ### Returns - **HttpServerHostContextBuilder** - The `HttpServerHostContextBuilder` instance, allowing for method chaining. ``` -------------------------------- ### RequestTraceIdentifier Property Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Cadente.CoreEngine.CadenteHttpServerEngineRequest.RequestTraceIdentifier.html Gets the request trace identifier. This property returns a Guid that uniquely identifies a specific request for tracing purposes. ```APIDOC ## RequestTraceIdentifier ### Description Gets the request trace identifier. ### Property `public override Guid RequestTraceIdentifier { get; }` ``` -------------------------------- ### Basic HTTP Server Builder Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.HttpServer.CreateBuilder.html Demonstrates how to create a basic HTTP server builder. This is the starting point for configuring and running an HTTP server. ```csharp var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddRazorPages(); var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.MapRazorPages(); app.Run(); ``` -------------------------------- ### Get One Value from IniSection Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.IniConfiguration.Core.IniSection.GetOne.html Retrieves a single value from a specified section in an INI configuration. This example demonstrates how to access a value using the GetOne method. ```csharp public static string GetOne(string section, string key, string defaultValue = "") { return GetOne(section, key, defaultValue); } ``` -------------------------------- ### C# Property Definition Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Documenting.Annotations.ApiResponseAttribute.ExampleLanguage.html Defines a property to get or set the programming language for examples. This is typically used in documentation generation to indicate the language of code snippets. ```csharp public string? ExampleLanguage { get; set; } ``` -------------------------------- ### Registering a Namespace with Custom Settings Source: https://github.com/sisk-http/docs/blob/master/_site/docs/cn/registering-namespace.html This example shows how to register a namespace with custom settings, such as specifying a display name and labels. This is useful for organizing and identifying namespaces. ```go package main import ( "context" "fmt" "github.com/cncf/xks/pkg/registry" ) func main() { ctx := context.Background() // Register a new namespace with custom settings. ns, err := registry.RegisterNamespace(ctx, "my-custom-namespace", registry.WithDisplayName("My Custom Namespace"), registry.WithLabels(map[string]string{ "environment": "production", "team": "backend", }), ) if err != nil { panic(err) } fmt.Printf("Namespace registered: %s\n", ns.ID) fmt.Printf("Display Name: %s\n", ns.DisplayName) fmt.Printf("Labels: %v\n", ns.Labels) } ``` -------------------------------- ### Use Cadente with Sisk Source: https://github.com/sisk-http/docs/blob/master/docs/cadente.md Configure the Sisk HttpServer to use CadenteHttpServerEngine for handling HTTP requests. This example demonstrates basic setup with SSL support for localhost. ```csharp using Sisk.Core.Http; using Sisk.Cadente.CoreEngine; using var host = HttpServer.CreateBuilder() .UseEngine() .UseSsl(certificate: CertificateHelper.CreateTrustedDevelopmentCertificate("localhost")) .Build(); await host.StartAsync(); ``` -------------------------------- ### CreateListener() - Random Port Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.HttpServer.CreateListener.html Use this method to get a listening and running HTTP server on a random port. No specific setup is required beyond calling the method. ```csharp public static HttpServer CreateListener() ``` -------------------------------- ### UseBootstraper with Named Asynchronous Action Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.Hosting.HttpServerHostContextBuilder.UseBootstraper.html Adds a named asynchronous action to be executed before the HTTP server starts. This allows for identifying and managing asynchronous setup tasks. ```csharp public HttpServerHostContextBuilder UseBootstraper(string name, Func asyncBootstrapAction) ``` -------------------------------- ### Serve Documentation Source: https://github.com/sisk-http/docs/blob/master/_site/readme.html This command serves the generated static documentation files using DocFX. The output will be available at the /_site directory. ```shell docfx serve ``` -------------------------------- ### UseBootstraper with Asynchronous Action Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.Hosting.HttpServerHostContextBuilder.UseBootstraper.html Adds an asynchronous action to be executed before the HTTP server starts. This is suitable for setup tasks that involve I/O operations or other asynchronous operations. ```csharp public HttpServerHostContextBuilder UseBootstraper(Func asyncBootstrapAction) ``` -------------------------------- ### Registering a Namespace with Default Settings Source: https://github.com/sisk-http/docs/blob/master/_site/docs/cn/registering-namespace.html This snippet demonstrates how to register a namespace using default configurations. Ensure the necessary imports are present. ```go package main import ( "context" "fmt" "github.com/cncf/xks/pkg/registry" ) func main() { ctx := context.Background() // Register a new namespace with default settings. ns, err := registry.RegisterNamespace(ctx, "my-namespace") if err != nil { panic(err) } fmt.Printf("Namespace registered: %s\n", ns.ID) } ``` -------------------------------- ### Get Random Port Example Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.ListeningPort.GetRandomPort.html Demonstrates how to obtain a random available port using the GetRandomPort method. This is useful for dynamically assigning ports to services during testing or development. ```csharp var port = ListeningPort.GetRandomPort(); Console.WriteLine($"Found available port: {port}"); ``` -------------------------------- ### Basic Authentication Handler Setup Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.BasicAuth.BasicAuthenticateRequestHandler.html Demonstrates how to set up and use the BasicAuthenticateRequestHandler for basic authentication. This involves creating an instance and potentially configuring it with user credentials. ```javascript const { BasicAuthenticateRequestHandler } = require('sisk.basicauth'); const handler = new BasicAuthenticateRequestHandler(); // Example usage within a Sisk server setup (conceptual) // server.addRequestHandler(handler); ``` -------------------------------- ### Emit Method Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.HttpServer.Emit.html Gets a non-listening HTTP server with configuration, listening host, and router. This method is useful for setting up an HTTP server instance without immediately starting it. ```APIDOC ## Emit ### Description Gets an non-listening HTTP server with configuration, listening host, and router. ### Method Signature `public static HttpServer Emit(ushort insecureHttpPort, out HttpServerConfiguration configuration, out ListeningHost host, out Router router)` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Parameters * **insecureHttpPort** (ushort) - Required - The insecure port where the HTTP server will listen. * **configuration** (HttpServerConfiguration) - Output - The [HttpServerConfiguration](Sisk.Core.Http.HttpServerConfiguration.html) object issued from this method. * **host** (ListeningHost) - Output - The [ListeningHost](Sisk.Core.Http.ListeningHost.html) object issued from this method. * **router** (Router) - Output - The [Router](Sisk.Core.Routing.Router.html) object issued from this method. ### Returns An instance of `HttpServer` that is configured but not yet listening. ``` -------------------------------- ### StartServer Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Cadente.CoreEngine.CadenteHttpServerEngine.html Starts the HTTP server. This method initiates the server's operation, making it ready to accept incoming connections. ```APIDOC ## StartServer() ### Description Starts the HTTP server. This method initiates the server's operation, making it ready to accept incoming connections. ### Method Not specified (likely a method call within the SDK) ### Parameters None ### Request Example None ### Response #### Success Response None #### Response Example None ``` -------------------------------- ### Conditional Request with IfNoneMatch Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Entity.HttpHeaderCollection.IfNoneMatch.html This example demonstrates how to use the IfNoneMatch property to make a conditional GET request. The request will only succeed if the ETag of the resource does not match any of the provided ETags. ```csharp using System.Net.Http; using Sisk.Core.Entity; // Assuming 'client' is an initialized HttpClient and 'requestUri' is the target URL var request = new HttpRequestMessage(HttpMethod.Get, requestUri); // Create an HttpHeaderCollection and set the IfNoneMatch property var headers = new HttpHeaderCollection(); headers.IfNoneMatch.Add("etag1"); headers.IfNoneMatch.Add("etag2"); // Add the IfNoneMatch headers to the request headers.AddToRequestMessage(request); // Send the request // var response = await client.SendAsync(request); // The response will be 304 Not Modified if the ETag matches any in the list. ``` -------------------------------- ### Find and Broadcast to SSE Connections Source: https://github.com/sisk-http/docs/blob/master/_site/docs/features/server-sent-events.html Search for active SSE connections using a predicate on their identifier and broadcast messages to them. This example finds all connections whose identifiers start with 'my-connection-'. ```csharp HttpRequestEventSource[] evs = server.EventSources.Find(es => es.StartsWith("my-connection-")); foreach (HttpRequestEventSource e in evs) { e.Send("Broadcasting to all event sources that starts with 'my-connection-'"); } ``` -------------------------------- ### StartServer() Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.Engine.HttpServerEngine.StartServer.html Starts the HTTP server. This is an abstract method that must be implemented by concrete server engine classes. ```APIDOC ## StartServer() ### Description Starts the HTTP server. ### Method `abstract void StartServer()` ### Remarks This is an abstract method and requires implementation in derived classes. ``` -------------------------------- ### RouteGetAttribute Constructor Example Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Routing.RouteGetAttribute.-ctor.html Demonstrates the basic usage of the RouteGetAttribute constructor to define a GET route. This is typically used to map a URL pattern to a specific handler or controller action. ```csharp using Sisk.Core.Routing; // ... [RouteGetAttribute("/api/users/{id}")] public class UsersController : IController { public void Get(int id) { // Handle GET request for a specific user } } ``` -------------------------------- ### Basic Request Handling Source: https://github.com/sisk-http/docs/blob/master/_site/docs/fundamentals/requests.html This snippet demonstrates how to set up a basic request handler for a given route. It shows how to access request details and send a simple response. ```go package main import ( "fmt" "net/http" "github.com/go-sisk/sisk" ) func main() { app := sisk.New() app.Get("/hello", func(ctx *sisk.Ctx) error { return ctx.SendString("Hello, World!") }) app.Listen(":3000") } ``` -------------------------------- ### Set Execution Permissions and Run Application Source: https://github.com/sisk-http/docs/blob/master/docs/deploying.md After transferring application files to the server, grant execute permissions to the binary and start the application. Replace 'my-app' with your actual application binary name. ```shell cd /home/htdocs chmod +x my-app ./my-app ``` -------------------------------- ### Writing to an HTTP Response Stream Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.Streams.HttpResponseStreamManager.GetStreamWriter.html Demonstrates how to obtain a stream writer for an HTTP response and write content to it asynchronously. This example shows the setup for converting HTML content to Markdown and copying it to the clipboard. ```javascript ener('click', async function() { const article = getArticleContent(); if (!article) return; if (typeof TurndownService === 'undefined') { const script = document.createElement('script'); script.src = 'https://unpkg.com/turndown/dist/turndown.js'; script.onload = function() { convertAndCopy(article); }; document.head.appendChild(script); } else { convertAndCopy(article); } copyDropdown.classList.remove('show'); }); function convertAndCopy(article) { const turndown = new TurndownService({ headingStyle: 'atx', codeBlockStyle: 'fenced' }); turndown.addRule('codeBlocks', { filter: ['pre'], replacement: function(content, node) { const code = node.querySelector('code'); const langClass = code?.className.match(/lang-(\w+)/); const lang = langClass ? langClass[1] : ''; const text = code?.textContent || content; return '\n\n```' + lang + '\n' + text.trim() + '\n```\n\n'; } }); const markdown = turndown.turndown(article.innerHTML); navigator.clipboard.writeText(markdown); } })(); ``` -------------------------------- ### XForwardedHost Property Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Entity.HttpHeaderCollection.XForwardedHost.html Gets the value of the HTTP X-Forwarded-Host header. This property is used to identify the original host requested by the client in the Host HTTP request header, often utilized in proxy setups. ```APIDOC ## Property XForwardedHost ### Description Gets the value of the HTTP X-Forwarded-Host header. Used to identify the original host requested by the client in the Host HTTP request header, often used in proxy setups. ### Property Value [string](https://learn.microsoft.com/dotnet/api/system.string) ``` -------------------------------- ### Example Usage of UsePortableConfiguration Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.Hosting.HttpServerHostContextBuilder.UsePortableConfiguration.html Demonstrates how to use the UsePortableConfiguration method to set up a portable configuration for the HTTP server host. This is useful for scenarios where configuration needs to be managed externally or in a flexible manner. ```csharp await new HttpServerHostContextBuilder() .UsePortableConfiguration(new PortableConfiguration("configuration.json")) .Build() .RunAsync(); ``` -------------------------------- ### TryGetValue Method Example Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Entity.TypedValueDictionary.TryGetValue.html Demonstrates how to use the TryGetValue method to safely retrieve a value from a TypedValueDictionary. This method is useful for checking if a key exists and getting its associated value without throwing an exception if the key is not found. ```csharp public bool TryGetValue(string key, [NotNullWhen(true)] out TResult? value) { if (TryGetValue(key, out var objValue)) { if (objValue is TResult result) { value = result; return true; } else { value = default; return false; } } else { value = default; return false; } } ``` -------------------------------- ### Initialize HttpServerEngine Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.Engine.HttpServerEngine.html Demonstrates the basic instantiation of the HttpServerEngine. This is the starting point for setting up an HTTP server with Sisk. ```csharp var engine = new HttpServerEngine(); ``` -------------------------------- ### Initialize Router Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Routing.Router.-ctor.html Demonstrates the basic initialization of a Router instance. This is the starting point for setting up routing in your Sisk application. ```csharp public Router(IServiceCollection services, IServiceProvider serviceProvider) ``` -------------------------------- ### Start mitmdump as a Reverse SSL Proxy Source: https://github.com/sisk-http/docs/blob/master/_site/docs/ssl.html Use mitmdump to create a reverse SSL proxy for your Sisk application. This allows you to intercept and manage HTTPS traffic. Ensure mitmproxy is installed and your Sisk application is running on a specified HTTP port. ```bash mitmdump --mode reverse:http://localhost:8000/ -p 8001 ``` -------------------------------- ### HttpServerHostContext.StartAsync Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.Hosting.HttpServerHostContext.StartAsync.html Initiates the asynchronous startup of the HTTP server host. This method is part of the core hosting functionality for the Sisk HTTP server. ```APIDOC ## HttpServerHostContext.StartAsync ### Description Starts the HTTP server host asynchronously. This is a crucial method for initializing and running the server. ### Method `StartAsync` ### Returns - **Task** - A Task representing the asynchronous operation of starting the server. ``` -------------------------------- ### Instantiate HttpServer Programmatically Source: https://github.com/sisk-http/docs/blob/master/_site/docs/deploying.html Example of manually instantiating an HttpServer and its configuration when not using Sisk.ServiceProvider. ```csharp HttpServer server = HttpServer.Emit(5000, out HttpServerConfiguration config, out var host, out var router); // sisk should listen on http://localhost:5000/ ``` -------------------------------- ### Navigate to Project Directory Source: https://github.com/sisk-http/docs/blob/master/_site/docs/getting-started.html Change your current directory to the newly created project folder. ```bash cd my-sisk-application ``` -------------------------------- ### HttpServerHandler Constructor Example Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.Handlers.HttpServerHandler.-ctor.html This snippet demonstrates the initialization of a script element and its subsequent loading and execution. It handles the conversion and copying of article content to the clipboard, utilizing the Turndown library for Markdown conversion. ```javascript var script = document.createElement('script'); script.src = 'https://unpkg.com/turndown/dist/turndown.js'; script.onload = function() { convertAndCopy(article); }; document.head.appendChild(script); } else { convertAndCopy(article); } copyDropdown.classList.remove('show'); }); function convertAndCopy(article) { const turndown = new TurndownService({ headingStyle: 'atx', codeBlockStyle: 'fenced' }); turndown.addRule('codeBlocks', { filter: ["pre"], replacement: function(content, node) { const code = node.querySelector('code'); const langClass = code?.className.match(/lang-(\w+)/); const lang = langClass ? langClass[1] : ''; const text = code?.textContent || content; return '\n\n```' + lang + '\n' + text.trim() + '\n```\n\n'; } }); const markdown = turndown.turndown(article.innerHTML); navigator.clipboard.writeText(markdown); } })(); ``` -------------------------------- ### Route Constructor Example Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Routing.Route.-ctor.html Demonstrates the basic instantiation of a Route object. This is the fundamental step for defining a new route in your application. ```csharp Route( "/", "GET", (req, res) => { res.send("Hello World!"); } ) ``` -------------------------------- ### ListeningHostSslOptions Constructors Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.ListeningHostSslOptions.html Initializes a new instance of the ListeningHostSslOptions class. ```APIDOC ## ListeningHostSslOptions(X509Certificate) ### Description Initializes a new instance of the ListeningHostSslOptions class. ### Parameters #### Path Parameters - **certificate** (X509Certificate) - Required - The SSL certificate to use. ``` -------------------------------- ### ApiEndpointRequestExample Class Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Documenting.html Represents an example request for an API endpoint, including its description and example content. ```APIDOC ## Class ApiEndpointRequestExample ### Description Represents an example request for an API endpoint, including its description and example content. ### Members - **description** (string) - A description of the request example. - **content** (string) - The example request content (e.g., JSON string). ``` -------------------------------- ### StartServer Method Signature Source: https://github.com/sisk-http/docs/blob/master/_site/api/Sisk.Core.Http.Engine.HttpServerEngine.StartServer.html This is the abstract method signature for starting the HTTP server. It indicates that subclasses must implement this method to provide the server's startup logic. ```csharp public abstract void StartServer() ```