[MUSIC] Okay, so here we are in our DataProviders.swift class and we're going to implement just the UserdataProvider for now since all we're going to do, at this point is try to create a user. We need to know where our server is on the internet and we are going to to do that by URL. So, at the top of this source file, outside of the classes. I'm going to just define some constants called server path, which contains the full URL for my server. And I'm also going to create a constant called end point. What we're trying to do is reach a controller class inside of the web servers that lives on this server. And those controllers are addressed by URLs that we call end points. So the final URL that we're going to try to reach is http://uci.smallfish.com/HBSRest- Dev/api/HobbyRest. And all of the web services calls, I may also refer to those as the rest calls, all of the rest calls we're going to do in this whole application are handled by the controller that lives at the HobbyRest end point. So now that we have those, we can start getting ready to make the call out to the server. Okay, so by this point, the user has typed in the user name, pressed the submit button, or they pressed the return key on the keyboard. We validated the form, we've called over to the data provider to make the call we're about to implement and go out to the web service. We've implemented everything this data provider is going to need to talk to the model class, and do the JSON serialization. And also get ready to handle to JSON de serialization. So now we just have to actually make the call. Remember, again, this call will always be used both for signing up, and for signing in. So I've named this function that we're about to implement, getAccountForUser. Because, that's what we really want to do, is we want to get these users account, so that we can use the user's ID that lives inside of that account. All right so let's see how that's accomplished. We're going to call this function here, getAccountForUser. And if we look back at our MeViewController, down here at the side of the submit function. That's the function that we're calling. So actually if I build it now, we should see that error go away. And it did, so that's good. So now we just need to implement that function. So first of all, we need to get everything we need to make the connection to the internet. So we'll say let requestUrlString. We're going to make a request to the server, an HTTP request. So we say our requestUrlString is equal to, like I told you, the server path plus the end point. Now we say let HTTPMethod equal the string CREATE_USER, so that's going to let the server know what we are trying to do. This is a custom verb that we've defined for this restful web service. Usually we would use a verb like, post or get or the standard rest verbs. We've created a custom verb called CREATE_USER to make it a little more obvious what you're doing. All right and now we need to create some memory for our user objects to go into that we're going to try to send to the server. So we create some space here called requestModel. And we accept the user that's passed in to us from our view controller that's calling this data provider function. All right. So now we have everything we need to make the call. So we can actually go ahead and create the code that will make the call for us. And that is this function called ajax and that lives inside of the SFL connection class that we're giving to you. So let's implement that function. You'll notice here that it takes the parameter's requestUrlString, so we pass in the request, or, excuse me, let me take that back. Let me do it like this. If I type in, ajax, so you can see the parameters that it takes. So it needs a URL to connect to, and needs to know which verb or HTTP method, in other words, that we're trying to do. And we need a requestBody that's the requestModel that we're trying to send to the server. And lastly, we need a completion block to respond on the client side to when we get the response from the server asynchronously. And again that's that trailing closure syntax that we saw in the view controller who was calling us. Right here's that trailing closure syntax. All right, so now let's go finish filling out this function. We need to reserve some memory for the returned user that's going to come back from the server. So we say let dict = NSDictionary. End it with dictionary the returnJSONDict. All right, and it's giving us a warning because we haven't used this variable yet. But we're about to. So, now we can say, Let the returned user be an instance of our user class. So user, and we call the default initializer. And then we say, returnedUser, readFromJSONDictionary, and then we pass in that dict that the server returned to us as JSON. So now we can see how this return, excuse me, readFromJSONDictionary deserializes the JSON information back into an instance of our user class. Finally, we want to call the completion block or the closure that our view controller passed into this function. So we can come down here and say completion. And this takes the argument of the object that was returned to us from the server, which in this case is returned user. So now we can give the returned user back to the view controller by calling this completion closure. [MUSIC]