iOS Network: 7 steps to apply a request

Source: Internet
Author: User

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

  1. 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
  2. Build the URL
    • Combine the base URL, the method being used, and the parameters to create the final URL for the request
  3. 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
  4. Make the request
    • Using the shared NSURLSession Singleton, issue the request and specify a completion handler
  5. 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 , ...
  6. Use the data!
    • Extract the data required for the specified task
  7. Start the request
    • To initiate the request, it must is started (resumed)

iOS Network: 7 steps to apply a request

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.