HBRouterGroup

public struct HBRouterGroup : HBRouterMethods

Used to group together routes under a single path. Additional middleware can be added to the endpoint and each route can add a suffix to the endpoint path

The code below creates an HBRouterGroupwith path “todos” and adds GET and PUT routes on “todos” and adds GET, PUT and DELETE routes on “todos/:id” where id is the identifier for the todo

app.router
.group("todos")
.get(use: todoController.list)
.put(use: todoController.create)
.get(":id", use: todoController.get)
.put(":id", use: todoController.update)
.delete(":id", use: todoController.delete)
  • Add middleware to RouterEndpoint

    Declaration

    Swift

    public func add(middleware: HBMiddleware) -> HBRouterGroup
  • Return a group inside the current group

    Declaration

    Swift

    public func group(_ path: String = "") -> HBRouterGroup

    Parameters

    path

    path prefix to add to routes inside this group

  • Add path for closure returning type conforming to ResponseFutureEncodable

    Declaration

    Swift

    @discardableResult
    public func on<Output: HBResponseGenerator>(
        _ path: String = "",
        method: HTTPMethod,
        options: HBRouterMethodOptions = [],
        use closure: @escaping (HBRequest) throws -> Output
    ) -> Self
  • Add path for closure returning type conforming to ResponseFutureEncodable

    Declaration

    Swift

    @discardableResult
    public func on<Output: HBResponseGenerator>(
        _ path: String = "",
        method: HTTPMethod,
        options: HBRouterMethodOptions = [],
        use closure: @escaping (HBRequest) -> EventLoopFuture<Output>
    ) -> Self