Mar 20, 2017
: ~ 13 min read

This is a bit tricky, since my routes for posts and pages are the same, and I differentiate between the two if I can create an Int out of the lastPathComponent. I know it's not the best approach, but since URLs should be permanent, I never moved to a /page/x structure. I also kind of dislike that structure ¯\_(ツ)_/¯.

In the first post in this series, I briefly presented the Droplet extension, with a very basic addRoutes method, just to present the methods in the extension itself. Let's give it a few routes:

extension Droplet {
func addRoutes() -> Droplet {
get("/feed", handler: FeedController.create)
get("/about", handler: AboutController.display)
// [...]
// Both these methods are resolved by the same method within `PageController`,
// but in the first case, a parameter named `id` can also be extracted.
get("/", ":id", handler: PageController.display)
get("/", handler: PageController.display)
return self
}
}

The make(_:with:for) method in the extension is used throughout the app instead of the default make(_:_:for:) so we can pass common parameters to all pages, required in the head and footer, for example.