Builder

open class Builder

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 a 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 /.

    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 a 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 /.

    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 a 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 /.

    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 a 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 /.

    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 a 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 /.

    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 a 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 /.

    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 a 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 /.

    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 /.

    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/node of Builder with RouteCollection.

    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 /.

    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/node of Builder.

  • Creates a new child instance/node of Builder with RouteCollection.

    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 /.

    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/node of Builder .