November 2018
Intermediate to advanced
404 pages
10h 16m
English
The handlers in the route group /journal/Int.parameter deal with a specific entry. The first handler belonging to this route group is getEntry():
func getEntry(_ req: Request) throws -> Entry { let index = try req.parameters.next(Int.self) // [1] let res = req.makeResponse() // [2] guard let entry = journal.read(index: index) else { throw Abort(.badRequest) } print("Read: \(entry)") try res.content.encode(entry, as: .formData) // [3] return entry}
There are several interesting steps in the preceding implementation:
Read now
Unlock full access