// IApiEndpoint.cs // SPDX-License-Identifier: GPL-3.0-or-later // SPDX-FileCopyrightText: 2025 Catswords OSS and WelsonJS Contributors // https://github.com/gnh1201/welsonjs // using System.Net; using System.Threading.Tasks; namespace WelsonJS.Launcher { /// /// Defines a contract for API endpoints that can selectively handle incoming HTTP requests. /// public interface IApiEndpoint { /// /// Determines whether this endpoint is able to handle the given HTTP request. /// /// /// This method is invoked by the request dispatcher to decide which endpoint /// should process the incoming request. /// /// Implementations may use the provided for fast /// routing decisions, while the full can be /// inspected for HTTP method, headers, query parameters, authentication /// state, or other request-specific information. /// /// This method should be free of side effects and must not write to the response. /// /// /// The HTTP listener context containing the incoming request details. /// /// /// The normalized request path extracted from the request URL /// (e.g. "/api/status"). /// /// /// true if this endpoint is responsible for handling the request; /// otherwise, false. /// bool CanHandle(HttpListenerContext context, string path); /// /// Asynchronously handles the HTTP request assigned to this endpoint. /// /// /// This method is called only after has returned /// true for the same request. /// /// Implementations are responsible for writing the response and properly /// terminating the request lifecycle. /// /// /// The HTTP listener context containing request and response objects. /// /// /// The request path associated with this endpoint. /// /// /// A task that represents the asynchronous handling operation. /// Task HandleAsync(HttpListenerContext context, string path); } }