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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
120
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
150
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
100
Claspは野良GASの夢をみるか
takter00
0
200
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.7k
Lessons from Spec-Driven Development
simas
PRO
0
210
C# and C++ Interoperability - cho-dotnetnew
harukasao
0
280
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
200
AIで効率化できた業務・日常
ochtum
0
140
Creating Composable Callables in Contemporary C++
rollbear
0
150
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.4k
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
850
Featured
See All Featured
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
310
Abbi's Birthday
coloredviolet
2
8.1k
How to train your dragon (web standard)
notwaldorf
97
6.7k
From π to Pie charts
rasagy
0
210
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.8k
The agentic SEO stack - context over prompts
schlessera
0
820
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
220
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Automating Front-end Workflow
addyosmani
1370
210k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
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