Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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
280
Other Decks in Technology
See All in Technology
まだ間に合う! Agentic AI on AWSの現在地をやさしく一挙おさらい
minorun365
14
1.5k
生成AI活用の型ハンズオン〜顧客課題起点で設計する7つのステップ
yushin_n
0
250
re:Invent 2025 ~何をする者であり、どこへいくのか~
tetutetu214
0
230
Database イノベーショントークを振り返る/reinvent-2025-database-innovation-talk-recap
emiki
0
240
年間40件以上の登壇を続けて見えた「本当の発信力」/ 20251213 Masaki Okuda
shift_evolve
PRO
1
140
AWS Security Agentの紹介/introducing-aws-security-agent
tomoki10
0
330
多様なデジタルアイデンティティを攻撃からどうやって守るのか / 20251212
ayokura
0
490
Databricks向けJupyter Kernelでデータサイエンティストの開発環境をAI-Readyにする / Data+AI World Tour Tokyo After Party
genda
1
600
GitHub Copilotを使いこなす 実例に学ぶAIコーディング活用術
74th
3
3.6k
【U/Day Tokyo 2025】Cygames流 最新スマートフォンゲームの技術設計 〜『Shadowverse: Worlds Beyond』におけるアーキテクチャ再設計の挑戦~
cygames
PRO
2
900
Strands Agents × インタリーブ思考 で変わるAIエージェント設計 / Strands Agents x Interleaved Thinking AI Agents
takanorig
3
1.1k
MariaDB Connector/C のcaching_sha2_passwordプラグインの仕様について
boro1234
0
930
Featured
See All Featured
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
110
Speed Design
sergeychernyshev
33
1.4k
Google's AI Overviews - The New Search
badams
0
860
Applied NLP in the Age of Generative AI
inesmontani
PRO
3
1.9k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
0
200
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
0
22
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
570
[RailsConf 2023] Rails as a piece of cake
palkan
58
6.2k
Writing Fast Ruby
sferik
630
62k
Art, The Web, and Tiny UX
lynnandtonic
304
21k
The agentic SEO stack - context over prompts
schlessera
0
550
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.8k
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