Splitting big tasks into small tasks are often one of the best ways to solve a problem. Thus, in the next few exercises, we'll split each request/method into a 7 step process. In the source code, I has commented each of these steps to assist you implement the requests.
7 Step Process
- Set the parameters
- Specify any parameters for the Web service method, that should is included in the final URL
- For example, if the final URL is https://api.themoviedb.org/3/authentication/token/new?api_key=ENTER_YOUR_API_KEY_ Here, and then, step should set the API key
- Build the URL
- Combine the base URL, the method being used, and the parameters to create the final URL for the request
- Configure the request
- Create a
NSURLRequest or NSMutableURLRequest using the URL
- (If necessary) When using a
NSMutableURLRequest , need to configure the request's header fields and HTTP body
- Make the request
- Using the shared
NSURLSession Singleton, issue the request and specify a completion handler
- Parse the data
- Assuming there is no error when the request returns, parse the response data to a usable type like a
NSDictionary , NSArray , or , ...
- Use the data!
- Extract the data required for the specified task
- Start the request
- To initiate the request, it must is started (resumed)
iOS Network: 7 steps to apply a request