Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cweinberger/bde3a6a1d8c4e5ff1a3ed3a20a463870 to your computer and use it in GitHub Desktop.
Save cweinberger/bde3a6a1d8c4e5ff1a3ed3a20a463870 to your computer and use it in GitHub Desktop.
func getBook(req: Request) throws -> Book {
guard
// 1
let bookIDString = req.parameters.get("bookID"),
// 2
let bookID = Int(bookIDString),
// 3
let book = Self.books.first(where: { $0.id == bookID })
else {
// 4
throw Abort(.notFound)
}
// 5
return book
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment