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

The Ecosystem of Web Development with Swift

The Ecosystem of Web Development with Swift

Shun Takebayashi

April 21, 2016
Tweet

More Decks by Shun Takebayashi

Other Decks in Programming

Transcript

  1. PerfectLib • First popular framework in Swift • Announced in

    November 2015 • Before Swift was open-sourced
  2. PerfectLib Application public func PerfectServerModuleInit() { Routing.Handler.registerGlobally() Routing.Routes["GET", "/hello"] =

    { _ in return HelloHandler() } } class HelloHandler: RequestHandler { func handleRequest(request: WebRequest, response: WebResponse) { response.appendBodyString("Hello, world!") response.requestCompletedCallback() } }
  3. Kitura let router = Router() router.get("/hello") { (request, response, next)

    in response.status(HttpStatusCode.OK).send("Hello, world").end() }
  4. Deploying Kitura Apps let router = Router() router.get("/hello") { (request,

    response, next) in response.status(HttpStatusCode.OK).send("Hello, world").end() } // Deploy Kitura-app with Kitura-net let server = HttpServer.listen(8080, delegate: router) Server.run()
  5. Problem: Tightly Coupled We can deploy • PerfectLib apps with

    PerfectServer • Kitua apps with Kitura-net
  6. Nest Application public protocol RequestType { var method: String {

    get } var path: String { get } var headers: [Header] { get } var body: PayloadType? { get set } } public protocol ResponseType { var statusLine: String { get } var headers: [Headers] { get } var body: PayloadType? { get set } } public typealias Application = RequestType -> ResponseType
  7. Nest Example import Inquiline let app: Application = { request:

    RequestType -> ResponseType in return Response(status: .Ok) }
  8. Nest Example import Inquiline let app: Application = { request:

    RequestType -> ResponseType in return Response(status: .Ok) } // Deploy with Curassow import Curassow serve(app)
  9. Nest Example import Inquiline let app: Application = { request:

    RequestType -> ResponseType in return Response(status: .Ok) } // Deploy with http4swift import http4swift let server = HTTPServer(port: 8080)! server.serve(app)
  10. What is OpenSwift? • Cross project standards for Swift •

    Sub-projects • C7 (Core components) • S4 (Server-side) • D5 (Database)
  11. S4 Application public protocol AsyncResponder { func respond( to request:

    Request, result: (Void throws -> Response) -> Void ) } public protocol Responder: AsyncResponder { func respond(to request: Request) throws -> Response }
  12. S4 Server public protocol AsyncServer { func serve( _ responder:

    AsyncResponder, on host: String, at port: Int ) throws } public protocol Server { func serve( _ responder: Responder, on host: String, at port: Int ) throws }
  13. Which Should We Use? Case • Your favorite framework supports

    Nest • Your favorite server supports S4 You can adopt adapters
  14. Conclusion • For app developers: • Use frameworks supporting Nest

    or S4 • For server/framework developers: • Implement based on Nest or S4