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

FrenchKit - Swift SuperPowers #1

FrenchKit - Swift SuperPowers #1

What swift can offer outside of Apple platforms?

This part is treating about the swift server part and it's dependencies.

David Bonnet

October 08, 2019
Tweet

More Decks by David Bonnet

Other Decks in Programming

Transcript

  1. write server-side code on top of Swift Standard Library cross-platform

    port of Foundation! https://github.com/apple/swift-corelibs-foundation you can !
  2. struct Talk var id: Int var name: String var date:

    Date } : Codable { let encoder = JSONEncoder() { "name": "Origins of life", "date": 592131600, "id": 42 }
  3. struct Talk var id: Int var name: String var date:

    Date } : Codable { let encoder = JSONEncoder() encoder.dateEncodingStrategy = .iso8601 { "name": "Origins of life", "date": "2019-10-07T09:00:00Z", "id": 42 }
  4. struct Talk var id: Int var name: String var date:

    Date } : Codable { let encoder = JSONEncoder() encoder.dateEncodingStrategy = .iso8601 { "name": "Origins of life", "date": "2019-10-07T09:00:00Z", "id": 42 } ⚠ https://github.com/apple/swift-corelibs-foundation/blob/master/Docs/Status.md
  5. use standard server services with swift ease of use! you

    can ! like the ones you hear every week
  6. struct Talk: Codable { var id: Int var name: String

    var date: Date } PostgreSQL Redis
  7. struct Talk: Codable { var id: Int var name: String

    var date: Date } PostgreSQL Amazon WebServices Redis struct Talk: Codable { var id: Int var name: String var date: Date var imageUrl: String }
  8. struct Talk: Codable { var id: Int var name: String

    var date: Date var imageUrl: String } PostgreSQL using vapor 3
  9. struct Talk: Codable { var id: Int var name: String

    var date: Date var imageUrl: String } extension Talk: PostgreSQLModel {} PostgreSQL using vapor 3 ?
  10. struct Talk: Codable { var id: Int var name: String

    var date: Date var imageUrl: String } extension Talk: PostgreSQLModel {} PostgreSQL using vapor 3 ? extension Talk: Migration {}
  11. PostgreSQL using vapor 3 // GET /talks func getAll(_ req:

    Request) throws -> Future<[Talk]> { return Talk.query(on: req).all() }
  12. PostgreSQL using vapor 3 // GET /talks func getAll(_ req:

    Request) throws -> Future<[Talk]> { return Talk.query(on: req).all() } // GET /talks?page=1&per=50 func getAllP(_ req: Request) throws -> Future<Paginated<Talk>> { let query = Talk.query(on: req) return try query.paginate(for: req) }
  13. PostgreSQL using vapor 3 // GET /talks?q=Robert func getAllP(_ req:

    Request) throws -> Future<Paginated<Talk>> { var query = Talk.query(on: req) .filter(\.imageUrl != nil) .sort(\.dateCreated, .descending) if let searchQuery = try? req.query.get(String.self, at: "q") { query = query.filter(\.name, .ilike, "%\(searchQuery)%") } return try query.paginate(for: req) }
  14. PostgreSQL using vapor 3 // POST /talks func create(_ req:

    Request, content: Talk.Create) throws -> Future<Talk> { let upload = try Storage.upload(bytes: content.imageData, fileName: content.filename, on: req) return upload.flatMap { imageUrl in let talk = Talk(name: content.name, date: content.date, imageUrl: imageUrl) return talk.save(on: req) } } Amazon WebServices
  15. server side swift write server-side code on top of Foundation

    supports many existing services PostgreSQL / MySQL / MongoDB / ... redis cache support Third party services connectors like AWS S3 try! Swift Tokyo 2019 Swift Server Update by Tom Doron (Apple) # $
  16. Wanna try? there is a classroom for that : please

    come and say hi David Bonnet - @iGranDav