Adding a Shopping List
To add a Shopping List to our app is as simple making a POST
request to the /shopping_lists
endpoint with the JSON representation of our Shopping List Model that we want to create. We need to make this request to our Vapor API server and wait for a success response that contains the newly created shopping list object in JSON format. We will then convert it to a ShoppingList
model and call the onCompletion
handler function that is passed so that the ShoppingListTableViewController
can add this new shopping list in its array of lists and tell the Table View to reload with this new Shopping List that is saved on the server.
To implement the add functionality that persists the new Shopping List in the database via our API, we need to follow these steps:
- Open the
ShoppingList.swift
file in the iOS project and add a new computed property calleddata
. This property will return an optional data type and it will return data in JSON format. We will useJSONSerializer
to convert...