Builder

open class Builder

Helps to build a tree of RouteCollections with Routes.

  • An instance of RouteCollection.

    Declaration

    Swift

    public var routes: RouteCollection
  • Initializes a new instance with another RouteCollection.

    Declaration

    Swift

    public init(_ routes: RouteCollection = .init())

    Parameters

    routes

    An instance of RouteCollection.

  • Creates a new instance of Route with the DELETE HTTP request method.

    Declaration

    Swift

    @discardableResult
    public func delete(
        _ path: String = Route.defaultPath,
        name: String = "",
        middleware: [Middleware] = .init(),
        handler: @escaping Route.Handler
    ) -> Route?

    Parameters

    path

    A path to a resource. Defaults to Route.defaultPath.

    name

    A unique name for Route. Defaults to an empty string.

    middleware

    An array of registered Middleware. Defaults to an empty array.

    handler

    A handler to call.

    Return Value

    A new instance of Route.

  • Creates a new instance of Route with the GET HTTP request method.

    Declaration

    Swift

    @discardableResult
    public func get(
        _ path: String = Route.defaultPath,
        name: String = "",
        middleware: [Middleware] = .init(),
        handler: @escaping Route.Handler
    ) -> Route?

    Parameters

    path

    A path to a resource. Defaults to Route.defaultPath.

    name

    A unique name for Route. Defaults to an empty string.

    middleware

    An array of registered Middleware. Defaults to an empty array.

    handler

    A handler to call.

    Return Value

    A new instance of Route.

  • Creates a new instance of Route with the HEAD HTTP request method.

    Declaration

    Swift

    @discardableResult
    public func head(
        _ path: String = Route.defaultPath,
        name: String = "",
        middleware: [Middleware] = .init(),
        handler: @escaping Route.Handler
    ) -> Route?

    Parameters

    path

    A path to a resource. Defaults to Route.defaultPath.

    name

    A unique name for Route. Defaults to an empty string.

    middleware

    An array of registered Middleware. Defaults to an empty array.

    handler

    A handler to call.

    Return Value

    A new instance of Route.

  • Creates a new instance of Route with the OPTIONS HTTP request method.

    Declaration

    Swift

    @discardableResult
    public func options(
        _ path: String = Route.defaultPath,
        name: String = "",
        middleware: [Middleware] = .init(),
        handler: @escaping Route.Handler
    ) -> Route?

    Parameters

    path

    A path to a resource. Defaults to Route.defaultPath.

    name

    A unique name for Route. Defaults to an empty string.

    middleware

    An array of registered Middleware. Defaults to an empty array.

    handler

    A handler to call.

    Return Value

    A new instance of Route.

  • Creates a new instance of Route with the PATCH HTTP request method.

    Declaration

    Swift

    @discardableResult
    public func patch(
        _ path: String = Route.defaultPath,
        name: String = "",
        middleware: [Middleware] = .init(),
        handler: @escaping Route.Handler
    ) -> Route?

    Parameters

    path

    A path to a resource. Defaults to Route.defaultPath.

    name

    A unique name for Route. Defaults to an empty string.

    middleware

    An array of registered Middleware. Defaults to an empty array.

    handler

    A handler to call.

    Return Value

    A new instance of Route.

  • Creates a new instance of Route with the POST HTTP request method.

    Declaration

    Swift

    @discardableResult
    public func post(
        _ path: String = Route.defaultPath,
        name: String = "",
        middleware: [Middleware] = .init(),
        handler: @escaping Route.Handler
    ) -> Route?

    Parameters

    path

    A path to a resource. Defaults to Route.defaultPath.

    name

    A unique name for Route. Defaults to an empty string.

    middleware

    An array of registered Middleware. Defaults to an empty array.

    handler

    A handler to call.

    Return Value

    A new instance of Route.

  • Creates a new instance of Route with the PUT HTTP request method.

    Declaration

    Swift

    @discardableResult
    public func put(
        _ path: String = Route.defaultPath,
        name: String = "",
        middleware: [Middleware] = .init(),
        handler: @escaping Route.Handler
    ) -> Route?

    Parameters

    path

    A path to a resource. Defaults to Route.defaultPath.

    name

    A unique name for Route. Defaults to an empty string.

    middleware

    An array of registered Middleware. Defaults to an empty array.

    handler

    A handler to call.

    Return Value

    A new instance of Route.

  • Creates an array with one or more instances of Route based on HTTP request methods provided.

    Declaration

    Swift

    @discardableResult
    public func request(
        _ path: String = Route.defaultPath,
        methods: Set<Request.Method> = Set(Request.Method.allCases),
        middleware: [Middleware] = .init(),
        handler: @escaping Route.Handler
    ) -> [Route]

    Parameters

    path

    A path to a resource. Defaults to Route.defaultPath.

    methods

    An array of HTTP request methods. Defaults to all supported HTTP request methods.

    middleware

    An array of registered Middleware. Defaults to an empty array.

    handler

    A handler to call.

    Return Value

    An array with one or more instances of Route.

  • Creates a new child instance of Builder with RouteCollection to group related Routes.

    Declaration

    Swift

    public func grouped(
        _ path: String = Route.defaultPath,
        name: String = "",
        middleware: [Middleware] = .init()
    ) -> Builder?

    Parameters

    path

    A path prefix to a resource. Defaults to Route.defaultPath.

    name

    A name prefix for Routes. Defaults to an empty string.

    middleware

    An array of registered Middleware. Defaults to an empty array.

    Return Value

    A new child instance of Builder.

  • Creates a new child instance of Builder with RouteCollection to group related Routes.

    Declaration

    Swift

    public func group(
        _ path: String = Route.defaultPath,
        name: String = "",
        middleware: [Middleware] = .init(),
        handler: @escaping (Builder) -> Void
    )

    Parameters

    path

    A path prefix to a resource. Defaults to Route.defaultPath.

    name

    A name prefix for Routes. Defaults to an empty string.

    middleware

    An array of registered Middleware. Defaults to an empty array.

    handler

    A handler with a new child instance of Builder .