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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
700
The Ecosystem of Web Development with Swift
takebayashi
4
1.3k
Other Decks in Programming
See All in Programming
AIキャラアプリkaiwaの低遅延音声通話基盤をどう作ったか - AWS Gravitonで支える低遅延・低コストAI Agent基盤
mogamit
0
180
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
500
今さら聞けない .NET CLI
htkym
0
100
才能?センス?知らん、 続けたもん勝ちだ。-- 結婚・出産・癌を越えてなお、私がプロダクトを創り続ける理由
16bitidol
2
900
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
0
320
関数型プログラミングのメリットって何だろう?
wanko_it
0
190
えっ!!コードを読まずに開発を!?
hananouchi
0
230
GDG Korea Android: 2026 I/O Extended ~ What's new in Android development tools
pluu
0
120
音楽のための関数型プログラミング言語mimiumにおける多段階計算の活用
tomoyanonymous
1
360
共通化で考えるべきは、実装より公開する型だった
codeegg
0
270
AI がコードを書く時代における新卒エンジニアの仕事風景 (2026) / New Graduate Engineers in the Era of AI Coding (2026)
sushichan044
0
230
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.6k
Featured
See All Featured
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.6k
Leo the Paperboy
mayatellez
8
1.9k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
430
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
240
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
620
The Cost Of JavaScript in 2023
addyosmani
55
10k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.7k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
250
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
370
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