new http and 3rd party librariestheshark/courses/cs329e/... · 2020. 4. 3. · using cocoapods from...
TRANSCRIPT
![Page 1: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/1.jpg)
University of Texas at AustinCS329eSpring 2020
HTTP and 3rd Party LibrariesDr. Sarah Abraham
![Page 2: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/2.jpg)
HTTP
✤ Hypertext Transfer Protocol
✤ Nodes contain hypertext
✤ Hyperlinks connect between nodes
✤ HTTP allows for the exchange and transfer of hypertext
✤ HTTP requests submitted to the server
✤ Server responds with message information and requested content
✤ HTML is hypertext markup language
![Page 3: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/3.jpg)
Messages
✤ HTTP messages consists of:
✤ Initial line
✤ Request: METHOD pathToRequestedURI HTTP/x.x
✤ Response: HTTP/x.x status_code reason
✤ Header information
✤ Header-Name: value
✤ https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
✤ Message body
![Page 4: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/4.jpg)
Status Codes
✤ Sent in initial line of responses
✤ Indicate success or failure of request
✤ Common status codes:
✤ 200 (ok)
✤ 404 (not found)
✤ 301 (moved permanently)
✤ 500 (server error)
![Page 5: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/5.jpg)
Other Status Codes
✤ 1xx (request received, continuing to process)
✤ 2xx (request received, understood, accepted and processed)
✤ 3xx (client must take additional action to complete request)
✤ 4xx (client error in request)
✤ 5xx (server error in fulfilling request)
![Page 6: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/6.jpg)
GET and HEAD Methods
✤ Retrieves information from given server at specified URI
✤ Does not modify data in any way
✤ GET retrieves headers and message body
✤ HEAD retrieves only the headers
![Page 7: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/7.jpg)
POST and PUT Methods
✤ Sends data to server
✤ Enclosed entity (block of data) sent with request
✤ POST method submits data to be processed by resource at URI
✤ URI is a program for handing this data
✤ Response is program’s output
✤ PUT method submits data to be stored at URI
![Page 8: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/8.jpg)
DELETE
✤ Removes all representations of the resource identified by URI
✤ Should flag cached representations of resource as stale
✤ That is, all representations — even those in cache — should be removed from the client’s view of the server
✤ Server can implement by deleting data or moving data to an inaccessible location
![Page 9: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/9.jpg)
Quiz Question!
✤ True or False: The POST and PUT method both send data to a server.
![Page 10: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/10.jpg)
REST
✤ REpresentational State Transfer
✤ Architecture and practices to provide interoperability between computers across the Internet
✤ Compliant systems access and manipulate web resources using predefined operations
✤ Responses provided via XML, HTML or JSON
✤ “Best practices” for using HTTP
![Page 11: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/11.jpg)
REST Properties
✤ Performance
✤ Scalability
✤ Simplicity
✤ Modifiability
✤ Visibility
✤ Portability
✤ Reliability
![Page 12: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/12.jpg)
REST Constraints
✤ Uniform Interface
✤ Stateless
✤ Cacheable
✤ Client-Server
✤ Layered System
✤ Code on Demand (optional)
![Page 13: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/13.jpg)
RESTful APIs
✤ Web service APIs that adhere to REST constraints
✤ Must have:
✤ A base URL
✤ Internet media type (MIME type)
✤ Standard HTTP methods
![Page 14: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/14.jpg)
AFNetworking/Alamofire
✤ Built on top of URLSession and Foundation’s URL Loading System
✤ Allows for easier HTTP requests and response handling without all the boilerplate code
✤ Example:
let request = Alamofire.request(.GET, “http://httpbin.org/get”)
request.validate() //Checks response status code
request.response { (request, response, data, error) in
}
![Page 15: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/15.jpg)
Importing Alamofire
✤ Xcode seamlessly handles importing built-in libraries
✤ You have been calling import UIKit at the top of every ViewController to import UIViewController functionality
✤ If a custom class is included in a project, Xcode automatically can link it into another class
✤ Alamofire is not built into Apple’s standard libraries
✤ Must import it as its own library
![Page 16: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/16.jpg)
Cocoapods
✤ Dependency manager for Swift projects
✤ Program knows about many libraries built for use in Swift/Objective-C
✤ Allows easy downloading of libraries
✤ Allows easy connecting of libraries to a project
✤ Standard way of managing libraries for Swift
![Page 17: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/17.jpg)
Installing Cocoapods
✤ Generally installed and use via command line
✤ There is an app (https://cocoapods.org/app) but frequently tools management is done from command line anyway…
✤ Command line is found under: Applications -> Utilities -> Terminal
✤ From terminal call sudo gem install cocoapods
✤ Built on Ruby (will work without additional installs on OSX)
✤ May have to provide user password
![Page 18: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/18.jpg)
Using Cocoapods
✤ From terminal, can call commands using pod
✤ pod init creates a file (Podfile) that manages libraries for the project (call from within project folder)
✤ Must manually add frameworks to the Podfile:platform :ios, '12.0' use_frameworks!
target 'MyApp' do
pod 'Alamofire', ‘5.0.0' #specifies versionend
![Page 19: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/19.jpg)
Installing Dependencies
✤ Once Podfile exists in project, must install all requested frameworks before they will connect to the project
✤ call pod install from within the project directory
✤ This will create a .xcworkspace file
✤ Must access project using .xcworkspace rather than .xcodeproj from now on
✤ Frameworks are not part of your project — workspace include your work and other files you need
![Page 20: New HTTP and 3rd Party Librariestheshark/courses/cs329e/... · 2020. 4. 3. · Using Cocoapods From terminal, can call commands using pod pod init creates a file (Podfile) that](https://reader035.vdocuments.net/reader035/viewer/2022071218/605301642569143d6b41ce2f/html5/thumbnails/20.jpg)
Workspace versus Project
xcodeproj space
workspace