April 2017
Intermediate to advanced
316 pages
9h 33m
English
The next operation that we need to implement is deleting items from our TodoStore. Let's implement the delete and deleteAll methods:
/// Delete a specific todo item drop.delete("deleteTodo") { request in guard let id = request.headers["id"]?.int else { return try JSON(node: ["message": "Please provide the id of todo item"]) } let todos = TodoStore.sharedInstance let message = todos.delete(id: id) return try JSON(node: ["message": message]) } /// Delete all items drop.delete("deleteAll") { request in let message = TodoStore.sharedInstance.deleteAll() return try JSON(node: ["message": message]) }
To test the delete functionality, we can execute the following commands in the terminal:
Read now
Unlock full access