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
710
The Ecosystem of Web Development with Swift
takebayashi
4
1.3k
Other Decks in Programming
See All in Programming
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
330
【QA Test Talk Vol.8】AI-DLC による Whole Team Approach の加速
pkshadeck
PRO
0
210
php-fpmのプロセスが枯渇した日-調査・対処・そして本当にやるべきだったこと-
shibuchaaaan
0
320
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
150
数百円から始めるRuby電子工作
tarosay
0
170
仕様駆動開発の消費期限
watany
20
8.7k
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
500
Go 1.27 における memory allocation の高速化
andpad
0
250
今さら聞けない .NET CLI
htkym
0
200
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
530
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
1.9k
リアルな遅延を測る仕様
kota_yata
1
120
Featured
See All Featured
The Curious Case for Waylosing
cassininazir
1
460
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
64
56k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
240
What's in a price? How to price your products and services
michaelherold
247
13k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.4k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
900
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
470
Rails Girls Zürich Keynote
gr2m
96
14k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
390
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.8k
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