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.
Ansible for KubernetesJeff Geerling
Ansible is a powerful infrastructure automation tool. Kubernetes is a powerful application deployment platform. Learn how to use these tools to automate massively-scalable, highly-available infrastructure.
Practical FP in Scala: A hands-on approachGabriel Volpe
A practical book aimed for those familiar with functional programming in Scala who are yet not confident about architecting an application from scratch.
Together, we will develop a purely functional application using the best libraries in the Cats ecosystem, while learning about design patterns and best practices.
Functional Design and ArchitectureAlexander Granin
Software Design in Functional Programming, Design Patterns and Practices, Methodologies and Application Architectures. How to build real software in Haskell with less efforts and low risks. The first complete source of knowledge.
Production HaskellMatt Parsons
Are you excited about Haskell, but don't know where to begin? Are you thrilled by the technical advantages, but worried about the unknown pitfalls? This book has you covered.
Tame your Work FlowSteve Tendon and Daniel Doiron
Do you need a high performance enterprise governance approach improving management, execution and delivery while dealing with multiple projects/products, events, stakeholders and teams? Giving you better bottom line results, faster time to market, less work, better predictability, happier employees, and delighted clients? Then learn about TameFlow!
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.
Machine Learning EngineeringAndriy Burkov
"If you intend to use machine learning to solve business problems at scale, I'm delighted you got your hands on this book."
—Cassie Kozyrkov, Chief Decision Scientist at Google
"Foundational work about the reality of building machine learning models in production."
—Karolis Urbonas, Head of Machine Learning and Science at Amazon
C++ Best PracticesJason Turner
Level up your C++, get the tools working for you, eliminate common problems, and move on to more exciting things!
Composing SoftwareEric Elliott
All software design is composition: the act of breaking complex problems down into smaller problems and composing those solutions. Most developers have a limited understanding of compositional techniques. It's time for that to change.
El Manual del ManagerKeyvan Akbary, Félix López, and Álvaro Salazar
¿Has deseado alguna vez el haber tenido una buena introducción al rol del Engineering Manager? En este libro aprenderás lo necesario para ejercer el rol de una manera efectiva: Expectativas y Responsabilidades del Rol, 1-1s, Ayudar a Crecer, Objetivos, Planes de Carrera, Cultura, Feedback, Contratación, Cultura de Producto y mucho más.
The Tester's Library
8 BooksThe Tester's Library consists of eight five-star books that every software tester should read and re-read. As bound books, this collection would cost over $200. Even as e-books, their price would exceed $80, but in this bundle, their cost is only $49.99. Here are the books, and why they should be in your library: Perfect Software and Other...
11 BooksIn this bundle, you will find 10 different agile books. They are about different aspects of being agile. - finding a job - doing coding dojo's - Retrospectives - Personal kanban - a non-typical coaching book and even a book that gives you an insight in the lives of some agile people.
WTFlop 6M + HU - Beta Bundle
Marionette.js A to Z
Build A Better Backbone App
3 BooksThe best way to learn new development skills is through experience, but that takes time you don't have.Get the best of both worlds with this bundle: you'll learn how to produce modern web applications by learning from experienced developers like Derick Bailey and David Sulc. BackboneJS is one of the favorite tools on the web today, but it...
General Systems Thinker Bundle
5 BooksThe General Systems Thinker Bundle is just that: a bundle of five books to advance the reader one giant step toward improved thinking, based on General Systems principles. Four of the books are the complete General Systems Series. The fifth is fictional piece which shows some general systems thinkers in action. It's a mystery in which a group of...
Experiential Learning Bundle
4 BooksThis bundle provides all four volumes of the popular Experiential Learning Series at a savings of $20 over the price if purchased separately.
2 BooksAfter getting up and running with Ansible in Jeff Geerling's Ansible for DevOps, strengthen your skills managing tens to thousands of instances and services in Amazon's AWS cloud with Yan Kurniawan's Ansible for AWS.
Learn ECMAScript 6 inside and out
2 BooksFor any technology, it helps to get multiple points of view on the functionality to get the best possible understanding. For ECMAScript 6/2015, no two resources are recommended more frequently thanExploring ES6by Dr. Axel Rauschmayer andUnderstanding ECMAScript 6by Nicholas C. Zakas. These two points of view, investigating the specification and...
Software architecture, for systems old and new
2 BooksThis bundle includes books about hands-on software architecture.