Request helper

Making a network request is easy to do in Swift using the Foundation framework by Apple. But having to type it out every time we need to make a network request can be verbose and tedious. So, for that purpose, it is best to create a helper function that we can call to make the network request. We will create a small helper function in our iOS project that will take a URL path and make a request to the host specified in the base URL of our Info.plist configuration file.

In this helper function, we can also pass the HTTP method we want to make and it will default to a GET request if it is not passed. We can also pass data to our helper method, which will be sent in the HTTP body of the request for the POST and PATCH requests. ...

Get Hands-On Full-Stack Development with Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.