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
Introduction of Swift HTTP APIs
Search
Shun Takebayashi
June 27, 2017
Programming
350
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Introduction of Swift HTTP APIs
Shun Takebayashi
June 27, 2017
More Decks by Shun Takebayashi
See All by Shun Takebayashi
はじめてのSwift Server API / Beginning Swift Server API
takebayashi
1
710
The Ecosystem of Web Development with Swift
takebayashi
4
1.3k
Other Decks in Programming
See All in Programming
FDEが実現するAI駆動経営の現在地
gonta
2
270
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
180
自動化したのに回らないテスト運用の壁ーAI時代の品質責任と生産性
mfunaki
0
130
テーブルをDELETEした
yuzneri
0
140
AI時代のPHPer生存戦略 ~「言語、もうなんでもよくない?」に本気で向き合う~
vivion
0
300
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
480
Android CLI
fornewid
0
210
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
210
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
260
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
300
VibeCodingからAgenticWorkflowへ
starfish719
0
330
the container ship “Apple Silicon”@WWDC26 Recap -Japan-\(region).swift
shingangan
0
110
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Un-Boring Meetings
codingconduct
0
380
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
330
Code Review Best Practice
trishagee
74
20k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
410
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
Fireside Chat
paigeccino
42
4k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
350
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
480
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
420
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Transcript
Introduction of Swift HTTP APIs Shun Takebayashi
History of Server-Side Swift
History of Server-Side Swift (Dec 2015) • Apple open-sourced Swift
History of Server-Side Swift ( - Mid 2016) • App
frameworks • Perfect • Kitura • No standard APIs • Third-party API specifications • Nest • OpenSwift / S4
The Ecosystem of Web Development with Swift Shun Takebayashi takebayashi
https://speakerdeck.com/takebayashi/the-ecosystem-of-web-development-with-swift
History of Server-Side Swift (Oct 2016) • Apple announces Server
APIs Work Group • Working on 3 layers: • Base networking • Security / Encryption • HTTP / WebSocket
͜Ε͔Β͡ΊΔ αʔόʔαΠυ Swift Tokyo Server Side Swift Meetup #7 @
Speee Lounge - 2017.5.26 https://speakerdeck.com/jp_pancake/korekarahazimerusabasaido-swift
What are HTTP APIs?
HTTP APIs are NOT… • Web application frameworks • Stable
specification
HTTP APIs are… • Low-level types and interfaces • Still
under discussion
Exploring HTTP APIs
https://github.com/swift-server/http/blob/develop/API.md
Types in HTTP APIs • HTTPRequest • HTTPResponse • HTTPResponseWriter
• HTTPBodyHandler • HTTPBodyProcessing • HTTPBodyChunk • etc…
Interfaces in HTTP APIs typealias WebApp = (HTTPRequest, HTTPResponseWriter) ->
HTTPBodyProcessing
Interfaces in HTTP APIs enum HTTPBodyProcessing { case discardBody case
processBody(handler: HTTPBodyHandler) } typealias HTTPBodyHandler = (HTTPBodyChunk, inout Bool) -> Void
Sample App let myApp = { (req: HTTPRequest, res: HTTPResponseWriter
) -> HTTPBodyProcessing in res.writeResponse(HTTPResponse( httpVersion: req.httpVersion, status: .ok, transferEncoding: .chunked, headers: HTTPHeaders([("Content-Type", "text/plain")]) )) return .processBody { (chunk, stop) in switch chunk { case .chunk(let data, let finishedProcessing): res.writeBody(data: data) { _ in finishedProcessing() } case .end: res.done() default: stop = true res.abort() } } }
Implementations
BlueSocketHTTP • Prototype implementation of HTTP APIs • Based on
IBM BlueSocket https://github.com/swift-server/http/tree/develop/Sources/BlueSocketHTTP
Deploying with BlueSocketHTTP import HTTP import BlueSocketHTTP let server =
BlueSocketSimpleServer() do { try server.start(port: 8080, webapp: myApp) }
Summary
Swift HTTP APIs are… • Low-level types and functions •
for handling/responding to requests • Unstable, but prototype implementations are available • You can try with BlueSocketHTTP
Happy Server-Side Swift