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
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
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
150
Oxcを導入して開発体験が向上した話
yug1224
4
320
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
140
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.6k
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
540
net-httpのHTTP/2対応について
naruse
0
500
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
200
Oxlintのカスタムルールの現況
syumai
6
1.1k
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4.3k
JJUG CCC 2026 Spring: JSpecify で実現する Kotlin フレンドリーな Java API 設計
ternbusty
1
180
New "Type" system on PicoRuby
pocke
1
980
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
120
Featured
See All Featured
A Soul's Torment
seathinner
6
3k
Navigating Team Friction
lara
192
16k
Music & Morning Musume
bryan
47
7.2k
The untapped power of vector embeddings
frankvandijk
2
1.8k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
How to train your dragon (web standard)
notwaldorf
97
6.7k
Docker and Python
trallard
47
3.9k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
370
From π to Pie charts
rasagy
0
210
Making the Leap to Tech Lead
cromwellryan
135
9.9k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
580
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