O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Deleting an item and deleting all Todo items

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:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required