iOS Apps with REST APIs
iOS Apps with REST APIs
Building Web-Driven Apps in Swift
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
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!
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
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
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
C++ Best PracticesJason Turner
Level up your C++, get the tools working for you, eliminate common problems, and move on to more exciting things!
Digital-First EventsJoep Piscaer and Jana Boruta
The only resource you will ever need to launch your digital events program.
C++20 is the next big C++ standard after C++11. As C++11 did it, C++20 changes the way we program modern C++. This change is, in particular, due to the big four of C++20: ranges, coroutines, concepts, and modules.
The book is almost daily updated. These incremental updates ease my interaction with the proofreaders.
Sockets and PipesType Classes
Sockets and Pipes is not an introduction to Haskell; it is an introduction to writing software in Haskell. Using a handful of everyday Haskell libraries, this book walks through reading the HTTP specification and implementing it to create a web server.
Atomic KotlinBruce Eckel and Svetlana Isakova
For both beginning and experienced programmers! From the author of the multi-award-winning Thinking in C++ and Thinking in Java together with a member of the Kotlin language team comes a book that breaks the concepts into small, easy-to-digest "atoms," along with exercises supported by hints and solutions directly inside IntelliJ IDEA!
Introducing EventStormingAlberto Brandolini
The deepest tutorial and explanation about EventStorming, straight from the inventor.
Cloud StrategyGregor Hohpe
“Strategy is the difference between making a wish and making it come true.” A successful migration to the cloud can transform your organization, but it shouldn’t be driven by wishes. This book tells you how to develop a sound strategy guided by frameworks and decision models without being overly abstract nor getting lost in product details.
Ansible for DevOpsJeff Geerling
Ansible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
node-opcua by exampleEtienne Rossignon
Get the best out of node-opcua through a set of documented examples by the author himself that will allow you to create stunning OPCUA Servers or Clients.
R Programming for Data ScienceRoger D. Peng
This book brings the fundamentals of R programming to you, using the same material developed as part of the industry-leading Johns Hopkins Data Science Specialization. The skills taught in this book will lay the foundation for you to begin your journey learning data science. Printed copies of this book are available through Lulu.
Software Architecture for Developers: Volumes 1 & 2 - Technical leadership and communication
2 Books"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before...
Django for Beginners/APIs/Professionals
CCIE Service Provider Ultimate Study Bundle
2 BooksPiotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification...
Cisco CCNA 200-301 Complet
4 BooksCe lot comprend les quatre volumes du guide préparation à l'examen de certification Cisco CCNA 200-301.
Linux Administration Complet
4 BooksCe lot comprend les quatre volumes du Guide Linux Administration :Linux Administration, Volume 1, Administration fondamentale : Guide pratique de préparation aux examens de certification LPIC 1, Linux Essentials, RHCSA et LFCS. Administration fondamentale. Introduction à Linux. Le Shell. Traitement du texte. Arborescence de fichiers. Sécurité...
Modern Management Made Easy
3 BooksRead all three Modern Management Made Easy books. Learn to manage yourself, lead and serve others, and lead the organization.
2 BooksDocker and Kubernetes are taking the world by storm! These books will get you up-to-speed fast! Docker Deep Dive is over 400 pages long, and covers all objectives on the Docker Certified Associate exam.The Kubernetes Book includes everything you need to get up and running with Kubernetes!
CCDE Practical Studies (All labs)
3 BooksCCDE lab
All the Books of The Medical Futurist
6 BooksWe put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy, digital health investments and how technology giants such as Amazon...
Cloud Architect: Transform Technology and Organization
2 BooksArchitects don't just recite product names and features. They understand the options, decisions, and trade-offs behind them. They earn credibility and maintain authenticity by connecting the penthouse with the engine room. Get two essential books that redefine the role of the software and IT architect at one low price:37 Things One Architect...