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

Server-Side Swift with Vapor

Server-Side Swift with Vapor

In this talk, I will briefly present the Swift language, its role in the back-end, and, more in depth, the Vapor framework.
Swift is an Open-Source language developed by Apple with speed, efficiency, friendly syntax and safety as its core values.
Vapor–pronounced /ˈveɪpə/–is an ultra modular and performatic framework for developing web apps, real-time apps, websites and APIs in Swift.

At the end I give a brief shout out to Rocket.Chat, my employer and sponsor for the event in which I gave this presentation.

Matheus Cardoso

July 17, 2018
Tweet

More Decks by Matheus Cardoso

Other Decks in Programming

Transcript

  1. class Cardoso: iOSDeveloper { let name = "Matheus Cardoso" let

    company = "Rocket.Chat" let github = "github.com/cardoso" let email = "[email protected]" }
  2. import Foundation public final class Message: Codable { public var

    id: Int? public var text: String public let dateCreated: Date public init(id: Int? = nil, text: String) { self.id = id self.text = text self.dateCreated = Date() } } Core
  3. Server import Vapor import FluentSQLite import SwiftChatCore extension Message: SQLiteModel

    { } extension Message: Migration { } extension Message: Content { } extension Message: Parameter { }
  4. Client import Foundation import SwiftChatCore func sendMessage(_ message: Message) {

    var request = URLRequest(url: messagesUrl) request.httpMethod = "POST" request.addValue(“application/json", forHTTPHeaderField: "Content-Type") request.httpBody = try? encoder.encode(message) URLSession.shared.dataTask(with: request).resume() }
  5. ASYNC func create(_ req: Request) throws -> Future<Message> { return

    try req.content.decode(Message.self).flatMap { $0.save(on: req) } }
  6. ASYNC func create(_ req: Request) throws -> Future<Message> { return

    try req.content.decode(Message.self).flatMap { $0.save(on: req) } }
  7. ASYNC func create(_ req: Request) throws -> Future<Message> { return

    try req.content.decode(Message.self).flatMap { $0.save(on: req) } }
  8. ASYNC func create(_ req: Request) throws -> Future<Message> { return

    try req.content.decode(Message.self).flatMap { $0.save(on: req) } }
  9. Conn 1 Conn 2 NIO-ELT-#0 Conn 3 Conn 4 NIO-ELT-#1

    Conn 5 Conn 6 NIO-ELT-#2 Conn 7 Conn 8 NIO-ELT-#3 Conn 9 Conn 10 NIO-ELT-#4 Conn 11 Conn 12 NIO-ELT-#5
  10. Droplet Config Auth Provider Router Views JSON Session VAPOR HTTP

    WSS SMTP ENGINE Model Driver FLUENT (ORM) Query Poly NODE Path CORE
  11. Droplet Config Auth Provider Router Views JSON Session VAPOR HTTP

    WSS SMTP ENGINE Model Driver FLUENT (ORM) Query Poly NODE Path CORE
  12. Droplet Config Auth Provider Router Views JSON Session VAPOR HTTP

    WSS SMTP ENGINE Model Driver FLUENT (ORM) Query Poly NODE Path CORE
  13. Path public protocol Provider { func register(_ services: inout Services)

    throws func willBoot(_ container: Container) throws -> Future<Void> func didBoot(_ container: Container) throws -> Future<Void> } public protocol VaporProvider: Provider { func willRun(_ worker: Container) throws -> Future<Void> func didRun(_ worker: Container) throws -> Future<Void> }
  14. Fun

  15. class Cardoso: iOSDeveloper { let name = "Matheus Cardoso" let

    company = "Rocket.Chat" let github = "github.com/cardoso" let email = "[email protected]" }