November 2018
Intermediate to advanced
404 pages
10h 16m
English
The handler for updating an entry is the second handler belonging to the /journal/Int.parameter route group:
func editEntry(_ req: Request) throws -> Future<HTTPStatus> { let index = try req.parameters.next(Int.self) let newID = UUID().uuidString return try req.content.decode(Entry.self).map(to: HTTPStatus.self) { entry in // [1] let newEntry = Entry(id: newID, title: entry.title, content: entry.content) guard let result = self.journal.update(index: index, entry: newEntry) else { throw Abort(.badRequest) } print("Updated: \(result)") return .ok }}
The line at [1] shows that the JSON object is decoded and serialized into an Entry object, and then an array containing HTTPStatus is returned from the mapping of a result using ...
Read now
Unlock full access