iOS Apps with REST APIs
This book is 100% complete
Completed on 2018-06-26
About the Book
Skip the hundreds of pages that barely get into how to make a network call in iOS. No esoteric details about Core Anything or mathematical proofs of flatmap. Only the nitty gritty that you need to get real work done now: interfacing with your web services and displaying the results in your UI.
This book was written using Swift 4, Alamofire 4.7, Xcode 9, and iOS 11 (with support for iOS 10).
All code samples included.
After reading this book you’ll be able to:
- Analyze a JSON response from a web service call and write Swift code to parse it into model objects.
- Display those model objects in a table view so that when the user launches the app they have a nice list to scroll through.
- Add authentication to use web service calls that require OAuth 2.0, a username/password, or a token.
- Transition from the main table view to a detail view for each object, possibly making another web service call to get more info about the object.
- Let users of your app add, modify and delete objects (as long as your web service supports it).
- Hook in to more web service calls to extend you app, like adding user profiles or letting users submit comments or attach photos to objects.
This book is for:
- Software developers getting started with iOS but experienced in other languages
- Front-end devs looking to implement native UIs for iOS apps (no CSS, oh noes!)
- Back-end devs tasked with getting the data into the user's hands on iOS
- Android, Windows Phone, Blackberry, Tizen, Symbian & Palm OS devs looking to expand their web service backed apps to iOS
- Anyone whose boss is standing over their shoulder asking why the data isn't showing up in the tableview yet
This book isn't for:
- People completely new to programming, you should have a decent grasp of at least one object-oriented programming language or have completed several intro to iOS tutorials
- Designers, managers, UX pros, ... It's a programming book. All the monospace font inserts will probably drive you crazy.
- Cross-platform developers dedicated to their tools (including HTML5 & Xamarin), this is all Swift & native UI, all the time
- Programmers building apps with no webservice interaction
- Game devs
1. From JSON API to Swift App
- 1.1 What Will You Be Able to Do?
- 1.2 Who Is This Book For?
- 1.3 Who Is This Book Not For?
- 1.4 Using This Book
- 1.5 What We Mean By Web Services / APIs / REST / CRUD
- 1.6 What about GraphQL?
- 1.7 JSON
- 1.8 Versions
- 1.9 Source Code
- 1.10 Disclaimer
- 1.11 Trademarks
2. Our App’s Requirements
- 2.1 Match Tasks to Endpoints
- 2.2 User Interface
- 2.3 API Requirements
- 2.4 Make a Plan
3. Swift JSON Parsing & Networking Calls 101
- 3.1 REST API Calls with URLSession
- 3.2 REST API Calls with Alamofire
4. Using a Router to Organize Alamofire Calls
- 4.1 Generating the URL Requests
- 4.2 Strongly Typed GET and POST Calls with Alamofire
- 4.3 And That’s All
5. Parsing JSON with Codable
- 5.1 Converting a Single Item to JSON
- 5.2 Convert an Array of Items to JSON
- 5.3 Generating JSON from an Item
- 5.4 Nested JSON Objects
- 5.5 What if the JSON Doesn’t Match My Struct / Object?
- 5.6 Some Warnings
- 5.7 And That’s Codable
- 5.8 And That’s All
- 6. Why I Use Libraries Like Alamofire
7. Hooking Up a REST API to a Table View
- 7.1 Our Swift Project
- 7.2 Analyzing the API JSON Response
- 7.3 Setting Up the Table View
- 7.4 Getting & Processing the API Response
- 7.5 And That’s All
8. Custom HTTP Headers
- 8.1 Per Request Headers
- 8.2 Session Custom Headers
- 8.3 Headers in URLRequestConvertible
- 8.4 Request Adapter
- 8.5 And That’s All For Headers
9. Loading UITableViewCell Images from an API
- 9.1 Loading Images from URLs
- 9.2 UITableViewCell Images from URLs
- 9.3 Enhancements
- 9.4 Caching Images
- 9.5 A Better Cache: PINRemoteImage
- 9.6 And That’s All
10. Pagination, a.k.a., Load More on Scroll
- 10.1 Where is the Next Page?
- 10.2 Fetching and Appending
- 10.3 Integrating with the View Controller
- 10.4 When to Load More Gists?
- 10.5 And That’s All for Pagination
11. Pull to Refresh
- 11.1 Adding Pull to Refresh
- 11.2 Showing the Last Refreshed Time
- 11.3 And That’s All
12. Authentication: Basic and HTTP Headers
- 12.1 The Docs
- 12.2 Basic Auth: Username/Password
- 12.3 HTTP Header Authentication
- 12.4 Alamofire Validation
- 12.5 And That’s All
13. Authentication: Implementing the OAuth 2.0 Flow
- 13.1 Get the OAuth Token
- 13.2 Login View
- 13.3 The OAuth Login Flow
- 13.4 Using the OAuth Token for API Calls
- 13.5 Storing the OAuth Token Securely
- 13.6 Making Authenticated Calls
- 13.7 And That’s the Login Flow for OAuth 2.0
14. Integrating OAuth with the UI
- 14.1 Error Handling During OAuth Login
- 14.2 Refresh Tokens
- 14.3 Unauthorized Responses: 404 vs 401
- 14.4 And That’s All
15. Switching Lists
- 15.1 Setting Up the UI
- 15.2 Sharing a Completion Handler
- 15.3 And That’s All
16. Switching Between View Controllers and More JSON Parsing
- 16.1 JSON Parsing: Dates
- 16.2 JSON Parsing: Dictionaries & Arrays
- 16.3 Configuring the Detail View Controller
- 16.4 Passing Data in a Segue
- 16.5 Adding a Table View
- 16.6 Displaying Gist File Content
- 16.7 And That’s All
17. Adding More API Calls - Starring
- 17.1 Is the Gist Starred?
- 17.2 Starred Status in the Table View
- 17.3 PUT and DELETE Calls to Star and Unstar Gists
- 17.4 Authorization Check
- 17.5 And That’s All
18. Deleting Gists
- 18.1 DELETE API Call
- 18.2 User Interface: Table View Delete Features
- 18.3 And That’s All
19. Creating Gists and Clearing the Cache
- 19.1 POST API Call with Nested JSON Parameters
- 19.2 Creating an Input Form with Validation
- 19.3 And That’s All
20. What if They’re Offline?
- 20.1 How Do We Know?
- 20.2 Verifying Offline Behavior
- 20.3 OAuth Offline
- 20.4 Save a Local Copy
- 20.5 Databases
21. What Next?
- 21.1 User Interface
- 21.2 Test the User Experience
- 21.3 Suggested Exercises
- 21.4 Did I Miss Anything?
A Brief Introduction to CocoaPods
- Adding a CocoaPod to a Project
- What Does the Podfile Mean?
- CocoaPods Version Numbers
- Updating CocoaPods
Expanded Edition: Book + TL;DR Edition + Adding More API Calls Reference Sheet
Get your app built faster. The TL;DR Edition will help guide you through the book to find the parts you need and get your app started. Then once you're on your way, the Adding More API Calls Reference Sheet will help you through all of the necessary steps each time you find yourself integrating yet another REST API call in your Swift app.
A team license for iOS Apps with REST APIs gives you freedom to distribute the book to your team members working for your company or collaborating on products with you - anyone working with your or for you on iOS apps. Includes the TL;DR Edition and Adding More API Calls Reference Sheet.
Sr. Architect Apple Products at Proscape Technologies
I had to comment on how you progressed from simple NSURLSession calls to Alamofire serializers. I really like how you explained why you would choose to use one vs. the other and how some libraries can dramatically simplify the code.
Director, North American Regions Applications at Estee Lauder Companies
I have always been a Microsoft developer and only recently gotten into iPhone development. Your book is exactly what myself and my team needed to get started. Every example was relevant to what we needed for the application we are developing.
Senior Developer at Volm Companies Inc
Your book made me a rockstar in my company :) I can't thank you enough!
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...