Server-side Swift experience and pitfalls coming from iOS
I have published a SDK for Swift to help developers to make their Clova skills. This presentation shows some problems I have faced through the development of the SDK and a sample project for it and solutions for them.
request 3. Process the Intent 4. Return the JSON response 1. Verify the request 2. Parse the JSON request 3. Process the Intent 4. Return the JSON response
Package.swift https://github.com/line/clova-cek-sdk-swift • Write handlers for: LaunchEvent IntentEvent SessionEndedEvent • Set environment variables: PORT APPLICATION_ID • Run the server
Tokyo’ • They provides a set of libraries CommonCrypto, OpenSSL, swift-ubuntu-docker, etc. • Good support in Swift@IBM slack channel • But I have not compared with other frameworks in detail
• docker and SPM • Some PaaS supports docker and can host HTTPS • swift-ubuntu-docker enables Swift build and run • SPM can contain both sample project and library in a single repository
immediately try it out • Contains the SDK as library Your project can include it in Package.swift products: [ .executable(name: "SampleApp", targets: ["SampleApp"]), .library( name: "AwesomeLibrary", targets: [“AwesomeLibrary"]), ], 1BDLBHFTXJGU
async processing? • Do not return a response object ! launchHandler(request:) -> CEKResponse • Let a developer to invoke a callback that takes a response object launchHandler(request:next:) -> ()
async processing? • Do not return a response object ! launchHandler(request:) -> CEKResponse • Let a developer to invoke a callback that takes a response object launchHandler(request:next:) -> () func launchHandler(request: CEKRequest, next: @escaping (CEKResponse) -> ()) -> () &YUFOTJPO3FRVFTU)BOEMFS
Use available library ex. SwiftyRequest • URLSession is not 100% implemented for Linux • Check the document for availability https://github.com/apple/swift-corelibs-foundation/blob/master/Docs/Status.md
library if possible • If not, work with proper libraries • Security Framework for macOS • OpenSSL for Linux https://www.openssl.org/docs/manmaster/man3/
macOS ≧ 10.12. How to Indicate OS version? • Attribute for if condition #available(OSX 10.12, *) • Build options for minimum target version swift build -Xswiftc "-target" -Xswiftc "x86_64-apple-macosx10.12"
return [ testCase(AwesomeLibraryTests.allTests), testCase(HelperMethodTests.allTests), ] } #endif 9$5FTU.BOJGFTUTTXJGU import AwesomeLibraryTests var tests = __allTests() XCTMain(tests) -JOVY.BJOTXJGU Test for Linux