Listing Todo items

To retrieve all Todo items, unlike our post call, we do not need to pass any header parameters, just cookie information. So, we add the following struct to handle this scenario:

struct RequestModel: RequestProtocol {     subscript(key: String) -> (String?, String?) {         get {             switch key {                 default: return ("Cookie","test=123")             }         }     } } 

Then, we can retrieve a list of Todo items using the following code:

sendRequest(Urls.getTodos, request: RequestModel()) {     (response, error) in     if error == nil {         let todos: [Todo]? = decode(response!)         completion(todos, nil)         print("request was successfull: \(todos)")     } else {         completion(nil, error)         print("Error: \(error?.localizedDescription)")     } } 

Although we added better error ...

Get Swift Functional Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.