Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route collections #421

Merged
merged 6 commits into from
Apr 29, 2024
Merged

Route collections #421

merged 6 commits into from
Apr 29, 2024

Conversation

adam-fowler
Copy link
Member

A route collection is a fragment of a router. It defines a selection of routes and middleware. RouterMethods has been altered slightly so that it can be used for RouteCollections as well as Router and RouterGroup.

struct UserController {
    var routes: RouteCollection<some BaseRequestContext> {
        let routes = RouteCollection()
        routes.post("signup", use: self.login)
        routes.group()
            .add(middleware: BasicAuthenticationMiddleware())
            .post("login", use: self.login)
        return routes
    }

    @Sendable func login(_ request: Request, context: some BaseRequestContext) -> HTTPResponse.Status {
        return .ok
    }
}

let router = Router()
router.add("/users", routes: UserController().routes)

Move all path manipulation in Router/RouterGroup to implementation of this function
Edited RouterGroup so it can be used with RouteCollection
@adam-fowler adam-fowler requested a review from Joannis April 21, 2024 10:34
adam-fowler and others added 2 commits April 29, 2024 10:22
Co-authored-by: Joannis Orlandos <joannis@orlandos.nl>
@adam-fowler adam-fowler merged commit ce5d492 into main Apr 29, 2024
4 of 5 checks passed
@adam-fowler adam-fowler deleted the route-collection branch April 29, 2024 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants