Skip to content

Instantly share code, notes, and snippets.

@reckenrode
Created April 7, 2018 23:14
Show Gist options
  • Save reckenrode/b0afc3d51622732a438f533792edac90 to your computer and use it in GitHub Desktop.
Save reckenrode/b0afc3d51622732a438f533792edac90 to your computer and use it in GitHub Desktop.
Router databinding configuration for my website
let router = try container.make(Router.self)
let blog = try container.make(BlogController.self)
router.get("blog", use: Template(path: "Blog/listing")
.bind(blog.posts, to: "posts")
.bind(blog.isOldestFirst, to: "oldest-first").fn())
router.get("blog", ":author", use: Template(path: "Blog/author-post").fn())
router.post("blog", ":save", use: (blog.save >>> { $0.redirect(to: "/blog") }))
router.get("blog", String.parameter, use: Template(path: "Blog/view-post")
.bindObject(blog.post).fn())
return .done(on: container)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment