Fetching data from the web
Retrieving data from the web is something that you will often do as an iOS professional. You won't just fetch data from a web service; you'll also send data back to it. For example, you might have to make an HTTP POST
request as part of a login flow or to update a user's profile information. Over time, iOS has evolved quite a bit in the web requests department, making it easier to use web services in apps.
Note
HTTP (or HTTPS) is a protocol that almost all web traffic uses for communication between a client, such as an app, and a server. The HTTP protocol supports several methods that signal the request's intent. GET
is used to retrieve information from a server. A POST
request indicates the intention to push new content to a server, for instance, submitting a form.
When you want to perform a web request in iOS, you will typically use the URLSession
class. The URLSession
class makes asynchronous web requests on your behalf. This means that iOS loads data from the...