Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Server Side Swift question

3652e140db258288623a0adf248baec0?s=47 Shinichi Goto
October 21, 2015
600

Server Side Swift question

3652e140db258288623a0adf248baec0?s=128

Shinichi Goto

October 21, 2015
Tweet

Transcript

  1. Server-Side Swift @_shingt 2015/10/21 LT@shibuya.swift#1

  2. Server-Side Swift?????????? @_shingt 2015/10/21 LT@shibuya.swift#1

  3. ୭ • Software Engineer @ Wantedly, Inc. • Twitter: @_shingt

    3
  4. Why Swift on server side • ʢօ͞Μ๨Ε͔͚ͯͦ͏ͳʣΦʔϓϯιʔεԽ • SwiftͰαʔόαΠυ΋ॻ͚ΔͷͰ͸ʁͬͯҰॠ੝ Γ্͕ͬͨʢؾ͕͢Δʣ

    • ࢓ࣄͰSwiftॻ͍ͯͳͯ͘ωλ͕ͳ͍ • ISUCON 4
  5. 5 http://isucon.net/

  6. ISUCON • WebΞϓϦέʔγϣϯͷύϑΥʔϚϯεɾ νϡʔχϯάίϯςετʢৄࡉུʣ • ࠓ೥͸SNSαΠτ͕୊ࡐ • αʔόαΠυॻ͘ͳΒ࿅शʹஸ౓ྑ͍ͷͰ͸ 6

  7. ISUCON • WebΞϓϦέʔγϣϯͷύϑΥʔϚϯεɾ νϡʔχϯάίϯςετʢৄࡉུʣ • ࠓ೥͸SNSαΠτ͕୊ࡐ • αʔόαΠυॻ͘ͳΒ࿅शʹஸ౓ྑ͍ͷͰ͸ 7 ܸ௜

  8. To work with server-side app • ࠷௿ݶ • HTTP Serverʢͱͯ͠ಈ͘ʣ

    • Template Engine • DBI, DB driver 8
  9. To work with server-side app • ࠷௿ݶ • HTTP Server

    • Template Engine • DBI, DB driver 9 GRMustache Swifter, Taylor
  10. ͱΓ͋͑ͣ࡞ͬͯΈͯΔͷͰ DEMO https://github.com/shingt/SwiftServerExamples

  11. HTTP server engine / fw • Swifter • ͦͦ͜͜੔ͬͯ͸͍Δ •

    https://github.com/glock45/swifter • Taylor • ͔ͳΓബ͍ & ·ͩػೳἧͬͯͳ͍ • GoͷMartiniϥΠΫʹॻ͚Δ • https://github.com/izqui/Taylor 11
  12. Swifter 12 import Swifter let server = HttpServer() server["/"] =

    { request in return .OK(.HTML("Hello World!")) } var e: NSError? if !server.start(3002, error: &e) { print("Server start error: \(e)") } else { NSRunLoop.mainRunLoop().run() }
  13. Swifter 13 import Swifter let server = HttpServer() server["/"] =

    { request in return .OK(.HTML("Hello World!")) } var e: NSError? if !server.start(3002, error: &e) { print("Server start error: \(e)") } else { NSRunLoop.mainRunLoop().run() }
  14. Taylor 14 import Taylor let server = Taylor.Server() server.get("/") {

    req, res, cb in res.bodyString = "Hello World!" cb(.Send(req, res)) } do { try server.serveHTTP(port: 3001, forever: true) } catch let e { print("Server start failed \(e)") }
  15. Taylor 15 import Taylor let server = Taylor.Server() server.get("/") {

    req, res, cb in res.bodyString = "Hello World!" cb(.Send(req, res)) } do { try server.serveHTTP(port: 3001, forever: true) } catch let e { print("Server start failed \(e)") }
  16. Swifter or Taylor • ΠϯλʔϑΣΠε͸ Taylor > Swifterʢݸਓత ʹ͸ʣ •

    ͕ɺTaylor͸·ͩ৭ʑ੔ͬͯͳ͍ • Swifter => CarthageରԠͯ͠ͳ͍ • αʔόαΠυతʹѻ͍ʹ͍͘ʁ 16
  17. Swifter or Taylor • ΠϯλʔϑΣΠε͸ Taylor > Swifterʢݸਓత ʹ͸ʣ •

    ͕ɺTaylor͸·ͩ৭ʑ੔ͬͯͳ͍ • Swifter => CarthageରԠͯ͠ͳ͍ • αʔόαΠυతʹѻ͍ʹ͍͘ʁ 17 cocoapods-rome
  18. cocoapods-rome

  19. cocoapods-rome • “pod install” ࣌ʹframeworkΛϏϧυͯ͘͠ΕΔcocoapods plugin • “Swift Scripting” by

    Ayaka Nonaka • https://realm.io/jp/news/swift-scripting/ 19
  20. cocoapods-rome 20 platform :osx, '10.10' pod 'Swifter', :git => 'https://

    github.com/glock45/swifter.git'
  21. cocoapods-rome 21 platform :osx, '10.10' plugin 'cocoapods-rome' pod 'Swifter', :git

    => 'https:// github.com/glock45/swifter.git'
  22. cocoapods-rome 22 APP_ROOT ├─ Podfile ├─ Pods/ │ ├─ Headers/

    │ ├─ Local Podspecs/ │ ├─ Pods.xcodeproj/ │ ├─ Swifter/ │ ├─ Target Support Files/ │ ├─ Manifest.lock ├─ Rome/ │ └─ Swifter.framework/ ├─ main.swift …
  23. cocoapods-rome 23 APP_ROOT ├─ Podfile ├─ Pods/ │ ├─ Headers/

    │ ├─ Local Podspecs/ │ ├─ Pods.xcodeproj/ │ ├─ Swifter/ │ ├─ Target Support Files/ │ ├─ Manifest.lock ├─ Rome/ │ └─ Swifter.framework/ ├─ main.swift …
  24. cocoapods-rome 24 APP_ROOT ├─ Podfile ├─ Pods/ │ ├─ Headers/

    │ ├─ Local Podspecs/ │ ├─ Pods.xcodeproj/ │ ├─ Swifter/ │ ├─ Target Support Files/ │ ├─ Manifest.lock ├─ Rome/ │ └─ Swifter.framework/ ├─ main.swift … swift -F Rome main.swift
  25. ࢥ͏ͱ͜Ζ • ͭΒ͍ ָ͍͠ʂʂʂ • ISUCONղ͜͏ͱͯ͠HTMLϨϯμ͚ͯͨ͠Ͳͦ΋ͦ΋JSONฦ ͤΕ͹े෼ͳͷͰ͸… • ॻ͚Δͷͱӡ༻͢ΔͷͱͰ͸·ͨ࿩͕ҧ͏͠ઌ௕ͦ͏ •

    Swift+αʔόαΠυͬΆ͍୯ޠͰݕࡧͯ͠΋OpenStackͱ͔ RubyͷSwift͕ग़ͯ͘Δ… • cocoapods-romeศར 25
  26. Thank you!