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
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
11
4.3k
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
140
ふつうのFeature Flag実践入門
irof
8
4k
RTSPクライアントを自作してみた話
simotin13
0
610
Oxlintのカスタムルールの現況
syumai
6
1.1k
A2UI という光を覗いてみる
satohjohn
1
140
The NotImplementedError Problem in Ruby
koic
1
840
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6.2k
dRuby over BLE
makicamel
2
380
Lessons from Spec-Driven Development
simas
PRO
0
210
Featured
See All Featured
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
180
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
180
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
Odyssey Design
rkendrick25
PRO
2
700
Accessibility Awareness
sabderemane
1
140
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Designing Powerful Visuals for Engaging Learning
tmiket
1
420
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Crafting Experiences
bethany
1
180
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Making Projects Easy
brettharned
120
6.7k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
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