November 2018
Intermediate to advanced
404 pages
10h 16m
English
Finally, you can put everything together by specifying all the endpoints that connect routes to handlers.
In the postInit() method of the App class, you're going to tell the router to direct appropriate HTTP requests to the CRUD Codable routes defined in JournalRoutes.swift:
func postInit() throws { let journalRoutes = JournalRoutes() // [1] // Endpoints initializeHealthRoutes(app: self) router.get("/journal") { _, response, _ in // [2] let total = journalRoutes.getTotal() response.send("\(total)") } router.post("/journal", handler: journalRoutes.newEntry) // [3] router.get("/journal", handler: journalRoutes.getEntry) // [4] router.put("/journal", handler: journalRoutes.editEntry) // [5] router.delete("/journal", ...Read now
Unlock full access