Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cweinberger/7ab6c22d69e918c78659fcd6be8ad3d3 to your computer and use it in GitHub Desktop.
Save cweinberger/7ab6c22d69e918c78659fcd6be8ad3d3 to your computer and use it in GitHub Desktop.
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