Last active
April 9, 2020 09:56
-
-
Save cweinberger/7ab6c22d69e918c78659fcd6be8ad3d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vapor | |
final class BookAPIController { | |
// 1 | |
struct Book: Content { | |
let id: Int | |
let title: String | |
let author: String | |
} | |
// 2 | |
static let books = [ | |
Book(id: 1, title: "Server Side Swift with Vapor", author: "raywenderlich.com"), | |
Book(id: 2, title: "Server Side Swift (Vapor Edition)", author: "Hacking with Swift"), | |
Book(id: 3, title: "Hands-On Swift 5 Microservices Development", author: "Ralph Kuepper") | |
] | |
// 3 | |
func getBooks(req: Request) -> [Book] { | |
return Self.books | |
} | |
} | |
// 4 | |
extension BookAPIController: RouteCollection { | |
// 5 | |
func boot(routes: RoutesBuilder) throws { | |
routes.get("", use: getBooks) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment