November 2018
Intermediate to advanced
404 pages
10h 16m
English
To update an existing item, you simply call the update() method:
// find an item by ID and replace itfunc updateItemHandler(id: Int, item: JournalItem, completion: @escaping(JournalItem?, RequestError?) -> Void) { item.update(id: id, completion)}
The updateItemHandler(item, completion) method expects both the ID of an existing item (decoded from the URL parameter) and a new JournalItem object (decoded from the request's JSON object).
You can also check the handler with the curl command:
curl --header "Content-Type: application/json" \--request PUT \--data '{"title":"New Update","content":"This is an update."}' \http://localhost:8080/api/admin/1
The item with ID 1 should have been updated by the updateItemHandler(id:item:completion:) ...
Read now
Unlock full access