Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Tiny Networking in Swift
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Chris Eidhof | @chriseidhof
December 09, 2014
Technology
2
19k
Tiny Networking in Swift
Chris Eidhof | @chriseidhof
December 09, 2014
Tweet
Share
More Decks by Chris Eidhof | @chriseidhof
See All by Chris Eidhof | @chriseidhof
Dutch FP Day 2015
chriseidhof
2
390
Functional Swift - Brooklyn
chriseidhof
3
1.3k
Functional Swift - SF
chriseidhof
6
26k
Functional Swift
chriseidhof
6
1.3k
Functional Swift
chriseidhof
1
160
Functional Programming in Swift
chriseidhof
40
19k
Lighter View Controllers
chriseidhof
4
210
Parsing with Blocks
chriseidhof
2
240
Practical Concurrent Programming
chriseidhof
4
290
Other Decks in Technology
See All in Technology
Kiro のクレジットを使い切る!
otanikohei2023
0
110
オンプレとGoogle Cloudを安全に繋ぐための、セキュア通信の勘所
waiwai2111
3
1.1k
チームメンバー迷わないIaC設計
hayama17
5
3.8k
作るべきものと向き合う - ecspresso 8年間の開発史から学ぶ技術選定 / 技術選定con findy 2026
fujiwara3
7
2.1k
クラウド時代における一時権限取得
krrrr38
1
160
EMからICへ、二周目人材としてAI全振りのプロダクト開発で見つけた武器
yug1224
3
390
Oracle Database@Google Cloud:サービス概要のご紹介
oracle4engineer
PRO
5
1.1k
自動テストが巻き起こした開発プロセス・チームの変化 / Impact of Automated Testing on Development Cycles and Team Dynamics
codmoninc
1
1.1k
生成AI活用によるPRレビュー改善の歩み
lycorptech_jp
PRO
5
2k
Evolution of Claude Code & How to use features
oikon48
1
190
EMからVPoEを経てCTOへ:マネジメントキャリアパスにおける葛藤と成長
kakehashi
PRO
6
850
JAWS DAYS 2026 CDP道場 事前説明会 / JAWS DAYS 2026 CDP Dojo briefing document
naospon
0
140
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.1k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.9k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
170
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
150
Practical Orchestrator
shlominoach
191
11k
RailsConf 2023
tenderlove
30
1.4k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
950
Ethics towards AI in product and experience design
skipperchong
2
210
Done Done
chrislema
186
16k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Tell your own story through comics
letsgokoyo
1
830
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.1k
Transcript
Tiny Networking @chriseidhof
$ pod install AlamoFire
Live coding!
$ rake routes | grep sign_in ... api_user_session POST /api/users/sign_in(.:format)
$ curl "http://localhost:3000/api/users/sign_in" \ -d "{\"email\": \"
[email protected]
\", \"password\": \"testtes\"}" \
--header "Content-Type:application/json" \ {"message":"Error with your login or password"}~
$ curl "http://localhost:3000/api/users/sign_in" -d "{\"email\": \"
[email protected]
\", \"password\": \"testtest\"}" --header "Content-Type:application/json"
{"auth_token":"8yBZFpqhagTJr6DpDSyS","email":"
[email protected]
"}
func apiRequest<A>( baseURL: NSURL, resource: Resource<A>, failure: () -> (),
completion: A -> () )
struct Resource<A> { let path: String let method : Method
let headers : [String:String] let requestBody: NSData? let parse: NSData -> A? }
typealias JSONDictionary = [String:AnyObject] func decodeJSON(data: NSData) -> JSONDictionary? func
encodeJSON(dictionary: JSONDictionary) -> NSData?
Usage
let parse : NSData -> String? = { data in
if let jsonDict = decodeJSON(data) { return jsonDict["auth_token"] as? String } return nil }
let requestParameters = ["email": "
[email protected]
", "password": "testtest"] let jsonBody =
encodeJSON(requestParameters)
let path = "api/users/sign_in" let headers = ["Content-Type": "application/json", "Accept":
"application/json"] let resource = Resource(path: path, method: .POST, requestBody: jsonBody, headers: headers, parse: parse)
let baseURL = NSURL(string:"http://localhost:3000")! apiRequest(baseURL, resource, { println("failure") }, {
authorizationToken in println("Auth token \(authorizationToken)") })
let email = "
[email protected]
" let password = "testtest" let baseURL
= NSURL(string:"http://localhost:3000")! let resource = login(email, password) apiRequest(baseURL, resource, { println("failure") }, { authorizationToken in println("Auth token \(authorizationToken)") })
More live coding!
Resources — https:/ /gist.github.com/chriseidhof/ 26bda788f13b3e8a279c — http:/ /chris.eidhof.nl/posts/tiny-networking-in- swift.html —
http:/ /www.objc.io/books/
Thanks?
None
None
None
None
None