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
Server-Side Swift @ Devoxx FR
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Simone Civetta
April 07, 2017
Programming
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Server-Side Swift @ Devoxx FR
Simone Civetta
April 07, 2017
More Decks by Simone Civetta
See All by Simone Civetta
2021: CI for Mobile: State of The Art
viteinfinite
0
390
MVI : une architecture robuste et moderne pour vos applications mobiles
viteinfinite
2
540
Cross-Platform Modules with Kotlin/Native (v. 2018.10)
viteinfinite
0
120
Face Recognition with Vision & Core ML
viteinfinite
1
1.1k
Shared Cross-Platform Modules with Kotlin/Native
viteinfinite
1
340
Swift on the Raspberry PI
viteinfinite
0
140
Server-Side Swift
viteinfinite
0
100
Be the Quality You Want to See in Your App [Swift Edition]
viteinfinite
1
440
Swift : Nouvelles du front
viteinfinite
0
120
Other Decks in Programming
See All in Programming
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
590
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
C# and C++ Interoperability - cho-dotnetnew
harukasao
0
280
net-httpのHTTP/2対応について
naruse
0
500
Oxcを導入して開発体験が向上した話
yug1224
4
320
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.7k
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
4
1.4k
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
540
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
370
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6.2k
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.3k
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
150
Featured
See All Featured
How to make the Groovebox
asonas
2
2.2k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
54k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
For a Future-Friendly Web
brad_frost
183
10k
Un-Boring Meetings
codingconduct
0
320
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
350
Git: the NoSQL Database
bkeepers
PRO
432
67k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
200
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
390
Everyday Curiosity
cassininazir
0
230
A designer walks into a library…
pauljervisheath
211
24k
Transcript
Swi! Côté Serveur 1
Salut 2
Simone Cive!a 3
Je suis un développeur iOS 4
7 ans 5
6
4 ans 7
8
9
10
11
12
13
Enfin... 14
Plan 1. Les Origines 2. État de l'art 3. Pourquoi
l'utiliser ? 4. Swift Server dans la vraie vie 5. Évolutions 15
1. Les origines 16
17
18
Pourquoi Open Source ? 19
20
21
22
23
24
2. État de l'art 25
Swi! 3.1 26
1.0 27
1.1 28
1.2 29
2.0 30
2.1 31
2.2 32
2.3 33
3.0 34
Swi! 3.1 35
En 2015-16 1 version tous les 2 mois 36
Un langage (presque) finalisé 37
Un langage complet 38
39
40
41
42
43
bibliothèques tierces 44
Beaucoup de bibliothèques tierces stables 45
46
47
48
Bibliothèques C 49
Frameworks Web 50
51
52
53
54
55
Swi! Package Manager 56
SPM swift package init swift package fetch swift package update
swift package generate-xcodeproj 57
Swi! Package Catalog 58
59
60
61
Quelques images Docker — swiftdocker/swift/ — ibmcom/kitura-ubuntu/ — zewo/todobackend/ 62
Qualité du code 63
64
65
66
67
Metriques de qualité Pour en savoir plus... speakerdeck.com/viteinfinite/be-the-quality-you-want- to-see-in-your-app-swift-edition 68
69
70
nuclide.io/docs/languages/swift/ 71
! 72
Enfin... 73
3. Pourquoi l'utiliser ? 74
Développement actif 75
76
77
78
79
80
81
Performance 82
Performance 83
Performance 84
Mémoire Source: http://benchmarksgame.alioth.debian.org 85
Applications isomorphes 86
GCD 87
4. Dans la vraie vie 88
89
90
L'application Serveur 1. Routing 2. Fichiers statiques 3. Proxy YouTube
4. Caching 91
Package.swi! import PackageDescription let package = Package( name: "XebiaTV", dependencies:
[ .Package(url: "https://github.com/vapor/vapor.git", majorVersion: 1, minor: 5), .Package(url: "https://github.com/vapor/redis-provider.git", majorVersion: 1) ] ) 92
Router import Foundation import Vapor let drop = Droplet() let
categoryController = CategoryController() let youtubeController = YouTubeController() drop.get("/categories", handler: categoryController.categories) drop.get("/playlistItems", handler: youtubeController.playlistItems) drop.get("/search", handler: youtubeController.search) drop.get("/live", handler: youtubeController.live) drop.get("/video", String.self, handler: youtubeController.video) drop.run() 93
Fichiers statiques import Foundation import Vapor import Core import HTTP
final class CategoryController { private let dataLoader = DataFile() func categories(_ req: Request) throws -> ResponseRepresentable { let fileBody = try dataLoader.load(path: drop.workDir + "Data/categories.json") return Response(body: .data(fileBody)) } } 94
Proxy YouTube public final class YouTubeController { // ... func
search(_ req: Request) throws -> ResponseRepresentable { let query = "\(googleApisBaseUrl)/search?key=\(apiKey)&channelId=\(channelId)" return try drop.client.get(query) } } 95
// ... public func video(_ req: Request, videoId: String) throws
-> ResponseRepresentable { let cacheKey = "video-\(videoId)" guard let cached = try cacheService.load(for: cacheKey) else { let urls = try videoUrls(for: videoId) try cacheService.save(node: urls, with: cacheKey, expiration: cacheExpiration) return try JSON(node: urls) } return try JSON(node: cached) } private func videoUrls(for videoId: String) throws -> Node { guard let urls = try LiveStreamerReader.read(videoId: videoId) else { throw Error.noVideo } return Node(["urls": Node.array(urls)]) } 96
Intégration avec LiveStreamer static func launch(_ command: String, args: [String]
= []) throws -> Data { #if os(Linux) let task = Task() #else let task = Process() #endif let pipe = Pipe() task.launchPath = command task.arguments = args task.standardOutput = pipe task.launch() let data = pipe.fileHandleForReading.readDataToEndOfFile() task.waitUntilExit() return data } 97
Cache avec Redis public protocol CacheService { func load(for key:
String) throws -> Node? func save(node: Node, with key: String, expiration: TimeInterval) throws } public class RedisService : CacheService { private let drop: Droplet public init(drop: Droplet) throws { try drop.addProvider(VaporRedis.Provider(config: drop.config)) self.drop = drop } public func load(for key: String) throws -> Node? { return try drop.cache.get(key) } public func save(node: Node, with key: String, expiration: TimeInterval) throws { try drop.cache.set(key, node) if let redisCache = drop.cache as? RedisCache { try redisCache.redbird.command("EXPIRE", params: [key, "\(Int(expiration))"]) } } } 98
Build $ swift build Compile CLibreSSL xts128.c Compile CLibreSSL x_x509a.c
Compile CLibreSSL xcbc_enc.c Compile CLibreSSL x_spki.c .... Compile Swift Module 'libc' (1 sources) Compile Swift Module 'SocksCore' (15 sources) Compile Swift Module 'Jay' (21 sources) Linking CLibreSSL Compile Swift Module 'Core' (28 sources) Compile Swift Module 'Routing' (11 sources) Compile Swift Module 'HTTPRouting' (5 sources) Compile Swift Module 'TypeSafeRouting' (3 sources) Compile Swift Module 'Cache' (3 sources) Compile Swift Module 'Auth' (15 sources) Compile Swift Module 'Vapor' (92 sources) Compile Swift Module 'VaporRedis' (2 sources) Compile Swift Module 'App' (6 sources) 99
Tests class AppTests: XCTestCase { // ... Create a StubCategoryController
func testCategoryRoute() throws { let drop = try makeTestDroplet(categoryController: StubCategoryController()) let request = try Request(method: .get, uri: "/categories") let response = try drop.respond(to: request) let jsonBody = try JSON(bytes: response.body.bytes!) XCTAssertEqual(jsonBody["categories"]?.string, "someCategory") } } 100
101
Tout s'est bien passé™ 102
Enfin... 103
104
105
Cross platform #if os(Linux) import Glibc #else import Darwin #endif
106
Swift Build 107
Swi! Package Manager Mess swift package generate-xcodeproj 108
Tester c'est linker (?) Undefined symbols for architecture x86_64: "test2.test2.init
() -> test2.test2", referenced from: test2Tests.test2Tests.(testExample () -> ()). (implicit closure #1) in test2Tests.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 109
5. Évolutions 110
Encore plus de Frameworks 111
Encore plus de APIs Swi! 112
113
114
Peut-on le déployer en prod ? 115
Oui ! 116
Enfin... 117
Merci ! 118
Simone Cive!a 119
Je suis un développeur iOS 120
Je suis un développeur Back 121
Enfin... 122
123
Be a Be!er Developer beabe!er.ninja 124
125