2026-07-19 00:47:49 +00:00
|
|
|
import Hummingbird
|
|
|
|
|
|
|
|
|
|
/// A type exposing its endpoints as a route collection ready to be added to a router.
|
|
|
|
|
///
|
2026-07-30 06:33:57 +00:00
|
|
|
/// Conforming controllers group related endpoints behind a single ``routes`` property, so the application composes them declaratively with
|
|
|
|
|
/// ``Hummingbird/RouterMethods/addController(_:)``:
|
2026-07-19 00:47:49 +00:00
|
|
|
///
|
|
|
|
|
/// ```swift
|
|
|
|
|
/// struct HealthController<Context: RequestContext>: RouterController {
|
|
|
|
|
/// var routes: RouteCollection<Context> {
|
|
|
|
|
/// RouteCollection(context: Context.self)
|
|
|
|
|
/// .get("health") { _, _ in HTTPResponse.Status.ok }
|
|
|
|
|
/// }
|
|
|
|
|
/// }
|
|
|
|
|
///
|
|
|
|
|
/// router.addController {
|
|
|
|
|
/// HealthController<AppRequestContext>()
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
|
|
|
|
public protocol RouterController<Context>: Sendable {
|
|
|
|
|
|
|
|
|
|
// MARK: Associated types
|
|
|
|
|
|
|
|
|
|
/// The request context the controller's routes operate on.
|
|
|
|
|
associatedtype Context: RequestContext
|
|
|
|
|
|
|
|
|
|
// MARK: Properties
|
|
|
|
|
|
|
|
|
|
/// The collection of routes the controller exposes.
|
|
|
|
|
var routes: RouteCollection<Context> { get }
|
|
|
|
|
|
|
|
|
|
}
|