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
380
Functional Swift - Brooklyn
chriseidhof
3
1.2k
Functional Swift - SF
chriseidhof
6
26k
Functional Swift
chriseidhof
6
1.2k
Functional Swift
chriseidhof
1
140
Functional Programming in Swift
chriseidhof
40
19k
Lighter View Controllers
chriseidhof
4
190
Parsing with Blocks
chriseidhof
2
230
Practical Concurrent Programming
chriseidhof
4
270
Other Decks in Technology
See All in Technology
AWSのマルチアカウント管理 ベストプラクティス最新版 2025 / Multi-Account management on AWS best practice 2025
ohmura
3
200
LangChainとLangGiraphによるRAG・AIエージェント実践入門「10章 要件定義書生成Alエージェントの開発」輪読会スライド
takaakiinada
0
120
LLM as プロダクト開発のパワードスーツ
layerx
PRO
1
190
AI Agentを「期待通り」に動かすために:設計アプローチの模索と現在地
kworkdev
PRO
2
380
.mdc駆動ナレッジマネジメント/.mdc-driven knowledge management
yodakeisuke
24
11k
20250408 AI Agent workshop
sakana_ai
PRO
15
3.3k
こんなデータマートは嫌だ。どんな? / waiwai-data-meetup-202504
shuntak
5
1.7k
FinOps_Demo
tkhresk
0
130
Рекомендации с нуля: как мы в Lamoda превратили главную страницу в ключевую точку входа для персонализированного шоппинга. Данил Комаров, Data Scientist, Lamoda Tech
lamodatech
0
140
CBになったのでEKSのこともっと知ってもらいたい!
daitak
1
150
Automatically generating types by running tests
sinsoku
1
400
システムとの会話から生まれる先手のDevOps
kakehashi
PRO
0
210
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
35
2.6k
Building Flexible Design Systems
yeseniaperezcruz
329
38k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
380
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
13
1.4k
Practical Orchestrator
shlominoach
186
10k
Building an army of robots
kneath
304
45k
It's Worth the Effort
3n
184
28k
Building Applications with DynamoDB
mza
94
6.3k
Optimising Largest Contentful Paint
csswizardry
36
3.2k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
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