From the course: iOS App Development: RESTful Web Services

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Create new object on the server

Create new object on the server - iOS Tutorial

From the course: iOS App Development: RESTful Web Services

Start my 1-month free trial

Create new object on the server

- [Instructor] In the previous video we saw how to use the encodable protocol on a class to be able to create a data instance of it that represents the object instance and all of its properties. Now we're going to look at something we can do with that data that is common for restful API. We're going to use it to post the data to the server. This is how you create an object on the server in a restful API. We're going to use the JSONEncoder instance to encode and get the data just like we saw before and then we'll set that as the HTTP body and send that up to the server and create a new instance. So in the code we want to run a new function on our music class. We're going to call this function saveToServer. So down here past at the bottom of our fetch function we'll add a new function on line 41. This is not going to be a static function, this will be a function we'll be able to call on any instacne of our class music. So we'll give it the name saveToServer and we don't need any…

Contents