April 2017
Intermediate to advanced
316 pages
9h 33m
English
The preceding call retrieves all the items. If we want to get a specific item, we can do that too as follows:
/// Get a specific todo item drop.get("todo") { in guard let id = request.headers["id"]?.int else { return try JSON(node: ["message": "Please provide the id of todo item"]) } let todos: [Todo] = TodoStore.sharedInstance.listItems() var json = [Todo]() let item = todos.filter { $0.todoId == id } if item.count > 0 { json.append(item[0]) } return try JSON(node: json) }
Here, we check for the existence of headers and use the listItems() method in our TodoStore class to retrieve that specific item. We can test it in curl by executing the following commands in the terminal:
curl -X "GET" "http://localhost:8080/todo/" ...
Read now
Unlock full access