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
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
200
Parsing with Blocks
chriseidhof
2
240
Practical Concurrent Programming
chriseidhof
4
290
Other Decks in Technology
See All in Technology
Security Hub と出会ってから 1年半が過ぎました
rch850
0
150
I tried making a solo advent calendar!
zzzzico
0
150
Kusakabe_面白いダッシュボードの表現方法
ykka
0
300
Data Intelligence on Lakehouse Paradigm
scotthsieh825
0
170
Hardware/Software Co-design: Motivations and reflections with respect to security
bcantrill
1
160
OCI技術資料 : OS管理ハブ 概要
ocise
2
4.1k
困ったCSVファイルの話
mottyzzz
0
310
コミュニティが持つ「学びと成長の場」としての作用 / RSGT2026
ama_ch
2
360
GitHub Copilot CLI 現状確認会議
torumakabe
8
2.3k
Eight Engineering Unit 紹介資料
sansan33
PRO
0
6.3k
Node vs Deno vs Bun 〜推しランタイムを見つけよう〜
kamekyame
1
530
迷わない!AI×MCP連携のリファレンスアーキテクチャ完全ガイド
cdataj
0
580
Featured
See All Featured
Accessibility Awareness
sabderemane
0
37
Site-Speed That Sticks
csswizardry
13
1k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
BBQ
matthewcrist
89
10k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
56
We Have a Design System, Now What?
morganepeng
54
8k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
61
51k
Designing for Timeless Needs
cassininazir
0
120
Building AI with AI
inesmontani
PRO
1
630
It's Worth the Effort
3n
188
29k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.3k
Stop Working from a Prison Cell
hatefulcrawdad
273
21k
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