SlideShare a Scribd company logo
1 of 88
Download to read offline
Codable

The key to Fullstack Swift
Swift Cloud Workshop 3

February 23rd, 2018
Chris Bailey

(@Chris__Bailey)
Codable
struct Profile {
var name: String
var photo: Data
var dateOfBirth: Date
}
let profile = Profile(name: “Chris”, photo: image, dateOfBirth: Date(“06-06-1980”))
struct Profile : Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
let profile = Profile(name: “Chris”, photo: image, dateOfBirth: Date(“06-06-1980”))
struct Profile : Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
let profile = Profile(name: “Chris”, photo: image, dateOfBirth: Date(“06-06-1980”))
let encoder = JSONEncoder()
let jsonData = try encoder.encode(profile)
struct Profile : Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
let profile = Profile(name: “Chris”, photo: image, dateOfBirth: Date(“06-06-1980”))
let encoder = JSONEncoder()
let jsonData = try encoder.encode(profile)
let decoder = JSONDecoder()
let person = try decoder.decode(Profile.self, from: jsonData)
Fullstack

Development
{
"name": "",
"photo": "",
"dateOfBirth": ""
}
{
"name": "",
"photo": "",
"dateOfBirth": {
"year":
"month":
"day":
}
}
struct Profile {
var name: String
var photo: Data
var dateOfBirth: Date
}
Swift
var profile: [String : Any]
Swift
KITURA
let profile = Profile(name: name, photo: photo)let json = JSON(data: data)

guard json["name"].exists() else {
response.status(.unprocessableEntity)
response.send(json: JSON([ "error": "Missing reqired property `name`" ]))
next()
}
guard let photo = Data(base64Encoded: photoString) else {
response.status(.unprocessableEntity)
response.send(json: JSON([ "error": "Type mismatch, `photo` expected to be Base64 encoded data" ]))
next()
}
guard let name = json["name"].string else {
response.status(.unprocessableEntity)
response.send(json: JSON([ "error": "Type mismatch, `name` expected to be a String" ]))
next()
}
guard json["photo"].exists() else {
response.status(.unprocessableEntity)
response.send(json: JSON([ "error": "Missing reqired property photo`" ]))
next()
}
guard let photoString = json[“photo"].string else {
response.status(.unprocessableEntity)
response.send(json: JSON([ "error": "Type mismatch, `photo` expected to be a String" ]))
next()
}
struct Profile {
var name: String
var photo: Data
var dateOfBirth: Date
}
Swift
struct Profile {
var name: String
var photo: Data
var dateOfBirth: Date
}
Swift Swift
KITURA
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
Swift Swift
KITURA
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
Swift Swift
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
KITURA
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
Swift Swift
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
let encoder = JSONEncoder()
let data = try encoder.encode(profile)
KITURA
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
Swift Swift
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
let decoder = JSONDecoder()
let person = try decoder.decode(Person.self, from: jsonData)
KITURA
{
"name": "",
"photo": "",
"dateOfBirth": ""
}
{
"name": "",
"photo": "",
"dateOfBirth": ""
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
Swift Swift
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
KITURA
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
Swift Swift
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
KITURA
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
Swift Swift
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
KITURA
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
Swift Swift
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
KITURA
Under the Hood
struct Profile {
var name: String
var photo: Data
var dateOfBirth: Date
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
extension Profile {
enum CodingKeys: String, CodingKey {
case name = "name"

case photo = "photo"
case dateOfBirth = "dateOfBirth"
}
}



struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
extension Profile {
enum CodingKeys: String, CodingKey {
case name = "name"

case photo = "photo"
case dateOfBirth = "dateOfBirth"
}
}



extension Profile : Decodable {
init(from decoder: Decoder) throws {
}
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
extension Profile {
enum CodingKeys: String, CodingKey {
case name = "name"

case photo = "photo"
case dateOfBirth = "dateOfBirth"
}
}



extension Profile : Decodable {
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)

}
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
extension Profile {
enum CodingKeys: String, CodingKey {
case name = "name"

case photo = "photo"
case dateOfBirth = "dateOfBirth"
}
}



extension Profile : Decodable {
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)

name = try values.decode(String.self, forKey: .name)
}
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
extension Profile {
enum CodingKeys: String, CodingKey {
case name = "name"

case photo = "photo"
case dateOfBirth = "dateOfBirth"
}
}



extension Profile : Decodable {
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)

name = try values.decode(String.self, forKey: .name)
photo = try values.decode(Data.self, forKey: .photo)
}
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
extension Profile {
enum CodingKeys: String, CodingKey {
case name = "name"

case photo = "photo"
case dateOfBirth = "dateOfBirth"
}
}



extension Profile : Decodable {
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)

name = try values.decode(String.self, forKey: .name)
photo = try values.decode(Data.self, forKey: .photo)
dateOfBirth = try values.decode(Date.self, forKey: .dateOfBirth)
}
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
extension Profile {
enum CodingKeys: String, CodingKey {
case name = "name"

case photo = "photo"
case dateOfBirth = "dateOfBirth"
}
}



extension Profile : Encodable {
func encode(to encoder: Encoder) throws {
}
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
extension Profile {
enum CodingKeys: String, CodingKey {
case name = "name"

case photo = "photo"
case dateOfBirth = "dateOfBirth"
}
}



extension Profile : Encodable {
func encode(to encoder: Encoder) throws {
var container = try encoder.container(keyedBy: CodingKeys.self)

}
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
extension Profile {
enum CodingKeys: String, CodingKey {
case name = "name"

case photo = "photo"
case dateOfBirth = "dateOfBirth"
}
}



extension Profile : Encodable {
func encode(to encoder: Encoder) throws {
var container = try encoder.container(keyedBy: CodingKeys.self)

try container.encode(name, forKey: .name)
try container.encode(photo, forKey: .photo)
try container.encode(dateOfBirth, forKey: .dateOfBirth)
}
}
Body Data
{
"name": "John Doe",
"photo": "jbbkj362",
"dateOfBirth": "06-06-1980“
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
router.get("/profile", handler: getProfiles)
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
router.get("/profile", handler: getProfiles)
func getProfiles(request: RouterRequest, response: RouterResponse, next: () -> Void) -> Void
{
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
router.get("/profile", handler: getProfiles)
func getProfiles(request: RouterRequest, response: RouterResponse, next: () -> Void) -> Void
{
var profile = request.read(as: Profile.Type)
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
router.get("/profile", handler: getProfiles)
func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void
{
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
router.get("/profile", handler: getProfiles)
func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void
{
...
respondWith(profiles, nil)
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
router.get("/profile", handler: getProfiles)
router.post("/profile", handler: addProfile)
func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void
{
...
respondWith(profiles, nil)
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
router.get("/profile", handler: getProfiles)
router.post("/profile", handler: addProfile)
func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void
{
...
respondWith(profiles, nil)
}
func addProfile(profile: Profile, respondWith: @escaping (Profile?, Error?) -> Void) -> Void
{
...
respondWith(profile, nil)
}
guard let backend = KituraKit(baseURL: "http://localhost:8080") else {
print("Error creating KituraKit client")
return
}
backend.get("/profile") { (profiles: [Profile]?, error: RequestError?) in
...
}
KITURAKIT
Query Parameters
GET: /profile?name=“John Doe”#
{
"name": "John Doe",
"photo": "jbbkj362",
"dateOfBirth": "06-06-1980“
}
{"name": "John Doe","photo": "jbbkj362","dateOfBirth": "06-06-1980"}
{"name": "John Doe" }
{"name": "John Doe"}
{“name"= "John Doe"}
{ name = "John Doe"}
? name = "John Doe"}
? name = "John Doe"#
?name="John Doe"#
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
router.get("/profile", handler: getProfiles)
func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void
{
...
respondWith(profiles, nil)
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
struct Query: QueryParams {
var name: String
}
router.get("/profile", handler: getProfiles)
func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void
{
...
respondWith(profiles, nil)
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
struct Query: QueryParams {
var name: String
}
router.get("/profile", handler: getProfiles)
func getProfiles( , respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void
{
...
respondWith(profiles, nil)
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
struct Query: QueryParams {
var name: String
}
router.get("/profile", handler: getProfiles)
func getProfiles(query: Query, respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void
{
...
respondWith(profiles, nil)
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
struct Query: QueryParams {
var name: String
}
router.get("/profile", handler: getProfiles)
func getProfiles(query: Query, respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void
{
...
respondWith(profiles , nil)
}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
struct Query: QueryParams {
var name: String
}
router.get("/profile", handler: getProfiles)
func getProfiles(query: Query, respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void
{
...
respondWith(profiles.filter{ ($0.name == query.name), nil)
}
What Else?
SELECT * from Profiles
name,, photo, dateOfBirth,
"John Doe", "jbbkj362", "06-06-1980",
name,, photo, dateOfBirth
"John Doe", "jbbkj362", "06-06-1980"
name:”John Doe”,photo:”jbbkj362”,dateOfBirth:”06-06-1980"
{name:”John Doe”,photo:”jbbkj362”,dateOfBirth:”06-06-1980”}
struct Profile: Codable {
var name: String
var photo: Data
var dateOfBirth: Date
}
router.get("/profile", handler: getProfiles)
func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void
{
...
respondWith(profiles, nil)
}
struct Profile: Model {
var name: String
var photo: Data
var dateOfBirth: Date
}
router.get("/profile", handler: getProfiles)
func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void
{
...
respondWith(profiles, nil)
}
struct Profile: Model {
var name: String
var photo: Data
var dateOfBirth: Date
}
router.get("/profile", handler: getProfiles)
func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void
{
Profile.getAll()
respondWith(profiles, nil)
}
struct Profile: Model {
var name: String
var photo: Data
var dateOfBirth: Date
}
router.get("/profile", handler: getProfiles)
func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void
{
Profile.getAll(respondWith)
respondWith(profiles, nil)
}
struct Profile: Model {
var name: String
var photo: Data
var dateOfBirth: Date
}
router.get("/profile", handler: getProfiles)
func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void
{
Profile.getAll(respondWith)
}
struct Profile: Model {
var name: String
var photo: Data
var dateOfBirth: Date
}
router.get("/profile", handler: getProfiles)
func getProfiles(completion: @escaping ([Profile]?, Error?) -> Void) -> Void
{
Profile.getAll(completion)
}
SELECT * from Profiles
SELECT * from Profiles
SELECT * from Profiles WHERE name = “John Doe”
struct Profile: Model {
var name: String
var photo: Data
var dateOfBirth: Date
}
router.get("/profile", handler: getProfiles)
func getProfiles(completion: @escaping ([Profile]?, Error?) -> Void) -> Void
{
Profile.getAll(completion)
}
struct Profile: Model {
var name: String
var photo: Data
var dateOfBirth: Date
}
struct Query: QueryParams {
var name: String
}
router.get("/profile", handler: getProfiles)
func getProfiles(completion: @escaping ([Profile]?, Error?) -> Void) -> Void
{
Profile.getAll(completion)
}
struct Profile: Model {
var name: String
var photo: Data
var dateOfBirth: Date
}
struct Query: QueryParams {
var name: String
}
router.get("/profile", handler: getProfiles)
func getProfiles(query: Query, completion: @escaping ([Profile]?, Error?) -> Void) -> Void
{
Profile.getAll(completion)
}
struct Profile: Model {
var name: String
var photo: Data
var dateOfBirth: Date
}
struct Query: QueryParams {
var name: String
}
router.get("/profile", handler: getProfiles)
func getProfiles(query: Query, completion: @escaping ([Profile]?, Error?) -> Void) -> Void
{
Profile.getAll( completion)
}
struct Profile: Model {
var name: String
var photo: Data
var dateOfBirth: Date
}
struct Query: QueryParams {
var name: String
}
router.get("/profile", handler: getProfiles)
func getProfiles(query: Query, completion: @escaping ([Profile]?, Error?) -> Void) -> Void
{
Profile.getAll(matching: query, completion)
}
Codable
Dynamic Swift
Questions

More Related Content

Similar to Swift Cloud Workshop - Codable, the key to Fullstack Swift

Persisting Data on SQLite using Room
Persisting Data on SQLite using RoomPersisting Data on SQLite using Room
Persisting Data on SQLite using RoomNelson Glauber Leal
 
Windows store app development using javascript
Windows store app development using javascriptWindows store app development using javascript
Windows store app development using javascriptFoyzul Karim
 
Code to copy Person.java .pdf
Code to copy Person.java .pdfCode to copy Person.java .pdf
Code to copy Person.java .pdfanokhijew
 
Kotlin Data Model
Kotlin Data ModelKotlin Data Model
Kotlin Data ModelKros Huang
 
SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"
SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"
SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"South Tyrol Free Software Conference
 
JSON and Swift, Still A Better Love Story Than Twilight
JSON and Swift, Still A Better Love Story Than TwilightJSON and Swift, Still A Better Love Story Than Twilight
JSON and Swift, Still A Better Love Story Than TwilightDonny Wals
 
GraphQL & Relay - 串起前後端世界的橋樑
GraphQL & Relay - 串起前後端世界的橋樑GraphQL & Relay - 串起前後端世界的橋樑
GraphQL & Relay - 串起前後端世界的橋樑Pokai Chang
 
Tools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionTools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionJesus Manuel Olivas
 
Avro, la puissance du binaire, la souplesse du JSON
Avro, la puissance du binaire, la souplesse du JSONAvro, la puissance du binaire, la souplesse du JSON
Avro, la puissance du binaire, la souplesse du JSONAlexandre Victoor
 
Snapshot Testing @ CocoaheadsNL
Snapshot Testing @ CocoaheadsNLSnapshot Testing @ CocoaheadsNL
Snapshot Testing @ CocoaheadsNLLars Lockefeer
 
main-cpp file #include -iostream- #include -vector- #include -Date-h.docx
main-cpp file #include -iostream- #include -vector-   #include -Date-h.docxmain-cpp file #include -iostream- #include -vector-   #include -Date-h.docx
main-cpp file #include -iostream- #include -vector- #include -Date-h.docxEvandWYAlland
 

Similar to Swift Cloud Workshop - Codable, the key to Fullstack Swift (12)

Persisting Data on SQLite using Room
Persisting Data on SQLite using RoomPersisting Data on SQLite using Room
Persisting Data on SQLite using Room
 
662305 09
662305 09662305 09
662305 09
 
Windows store app development using javascript
Windows store app development using javascriptWindows store app development using javascript
Windows store app development using javascript
 
Code to copy Person.java .pdf
Code to copy Person.java .pdfCode to copy Person.java .pdf
Code to copy Person.java .pdf
 
Kotlin Data Model
Kotlin Data ModelKotlin Data Model
Kotlin Data Model
 
SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"
SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"
SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"
 
JSON and Swift, Still A Better Love Story Than Twilight
JSON and Swift, Still A Better Love Story Than TwilightJSON and Swift, Still A Better Love Story Than Twilight
JSON and Swift, Still A Better Love Story Than Twilight
 
GraphQL & Relay - 串起前後端世界的橋樑
GraphQL & Relay - 串起前後端世界的橋樑GraphQL & Relay - 串起前後端世界的橋樑
GraphQL & Relay - 串起前後端世界的橋樑
 
Tools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionTools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 Edition
 
Avro, la puissance du binaire, la souplesse du JSON
Avro, la puissance du binaire, la souplesse du JSONAvro, la puissance du binaire, la souplesse du JSON
Avro, la puissance du binaire, la souplesse du JSON
 
Snapshot Testing @ CocoaheadsNL
Snapshot Testing @ CocoaheadsNLSnapshot Testing @ CocoaheadsNL
Snapshot Testing @ CocoaheadsNL
 
main-cpp file #include -iostream- #include -vector- #include -Date-h.docx
main-cpp file #include -iostream- #include -vector-   #include -Date-h.docxmain-cpp file #include -iostream- #include -vector-   #include -Date-h.docx
main-cpp file #include -iostream- #include -vector- #include -Date-h.docx
 

More from Chris Bailey

NodeJS Interactive 2019: FaaS meets Frameworks
NodeJS Interactive 2019:  FaaS meets FrameworksNodeJS Interactive 2019:  FaaS meets Frameworks
NodeJS Interactive 2019: FaaS meets FrameworksChris Bailey
 
Voxxed Micro-services: Serverless JakartaEE - JAX-RS comes to FaaS
Voxxed Micro-services: Serverless JakartaEE - JAX-RS comes to FaaSVoxxed Micro-services: Serverless JakartaEE - JAX-RS comes to FaaS
Voxxed Micro-services: Serverless JakartaEE - JAX-RS comes to FaaSChris Bailey
 
Silicon Valley Code Camp 2019 - Reaching the Cloud Native World
Silicon Valley Code Camp 2019 - Reaching the Cloud Native WorldSilicon Valley Code Camp 2019 - Reaching the Cloud Native World
Silicon Valley Code Camp 2019 - Reaching the Cloud Native WorldChris Bailey
 
FaaS Meets Java EE: Developing Cloud Native Applications at Speed
FaaS Meets Java EE: Developing Cloud Native Applications at SpeedFaaS Meets Java EE: Developing Cloud Native Applications at Speed
FaaS Meets Java EE: Developing Cloud Native Applications at SpeedChris Bailey
 
AltConf 2019: Server-Side Swift State of the Union
AltConf 2019:  Server-Side Swift State of the UnionAltConf 2019:  Server-Side Swift State of the Union
AltConf 2019: Server-Side Swift State of the UnionChris Bailey
 
Server-side Swift with Swagger
Server-side Swift with SwaggerServer-side Swift with Swagger
Server-side Swift with SwaggerChris Bailey
 
Node Summit 2018: Cloud Native Node.js
Node Summit 2018: Cloud Native Node.jsNode Summit 2018: Cloud Native Node.js
Node Summit 2018: Cloud Native Node.jsChris Bailey
 
Index - BFFs vs GraphQL
Index - BFFs vs GraphQLIndex - BFFs vs GraphQL
Index - BFFs vs GraphQLChris Bailey
 
Swift Cloud Workshop - Swift Microservices
Swift Cloud Workshop - Swift MicroservicesSwift Cloud Workshop - Swift Microservices
Swift Cloud Workshop - Swift MicroservicesChris Bailey
 
Swift Summit 2017: Server Swift State of the Union
Swift Summit 2017: Server Swift State of the UnionSwift Summit 2017: Server Swift State of the Union
Swift Summit 2017: Server Swift State of the UnionChris Bailey
 
IBM Cloud University: Build, Deploy and Scale Node.js Microservices
IBM Cloud University: Build, Deploy and Scale Node.js MicroservicesIBM Cloud University: Build, Deploy and Scale Node.js Microservices
IBM Cloud University: Build, Deploy and Scale Node.js MicroservicesChris Bailey
 
IBM Cloud University: Java, Node.js and Swift
IBM Cloud University: Java, Node.js and SwiftIBM Cloud University: Java, Node.js and Swift
IBM Cloud University: Java, Node.js and SwiftChris Bailey
 
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
Node Interactive: Node.js Performance and Highly Scalable Micro-ServicesNode Interactive: Node.js Performance and Highly Scalable Micro-Services
Node Interactive: Node.js Performance and Highly Scalable Micro-ServicesChris Bailey
 
FrenchKit 2017: Server(less) Swift
FrenchKit 2017: Server(less) SwiftFrenchKit 2017: Server(less) Swift
FrenchKit 2017: Server(less) SwiftChris Bailey
 
AltConf 2017: Full Stack Swift in 30 Minutes
AltConf 2017: Full Stack Swift in 30 MinutesAltConf 2017: Full Stack Swift in 30 Minutes
AltConf 2017: Full Stack Swift in 30 MinutesChris Bailey
 
InterConnect: Server Side Swift for Java Developers
InterConnect:  Server Side Swift for Java DevelopersInterConnect:  Server Side Swift for Java Developers
InterConnect: Server Side Swift for Java DevelopersChris Bailey
 
InterConnect: Java, Node.js and Swift - Which, Why and When
InterConnect: Java, Node.js and Swift - Which, Why and WhenInterConnect: Java, Node.js and Swift - Which, Why and When
InterConnect: Java, Node.js and Swift - Which, Why and WhenChris Bailey
 
Playgrounds: Mobile + Swift = BFF
Playgrounds: Mobile + Swift = BFFPlaygrounds: Mobile + Swift = BFF
Playgrounds: Mobile + Swift = BFFChris Bailey
 
Swift Summit: Pushing the boundaries of Swift to the Server
Swift Summit: Pushing the boundaries of Swift to the ServerSwift Summit: Pushing the boundaries of Swift to the Server
Swift Summit: Pushing the boundaries of Swift to the ServerChris Bailey
 
O'Reilly Software Architecture Conf: Cloud Economics
O'Reilly Software Architecture Conf: Cloud EconomicsO'Reilly Software Architecture Conf: Cloud Economics
O'Reilly Software Architecture Conf: Cloud EconomicsChris Bailey
 

More from Chris Bailey (20)

NodeJS Interactive 2019: FaaS meets Frameworks
NodeJS Interactive 2019:  FaaS meets FrameworksNodeJS Interactive 2019:  FaaS meets Frameworks
NodeJS Interactive 2019: FaaS meets Frameworks
 
Voxxed Micro-services: Serverless JakartaEE - JAX-RS comes to FaaS
Voxxed Micro-services: Serverless JakartaEE - JAX-RS comes to FaaSVoxxed Micro-services: Serverless JakartaEE - JAX-RS comes to FaaS
Voxxed Micro-services: Serverless JakartaEE - JAX-RS comes to FaaS
 
Silicon Valley Code Camp 2019 - Reaching the Cloud Native World
Silicon Valley Code Camp 2019 - Reaching the Cloud Native WorldSilicon Valley Code Camp 2019 - Reaching the Cloud Native World
Silicon Valley Code Camp 2019 - Reaching the Cloud Native World
 
FaaS Meets Java EE: Developing Cloud Native Applications at Speed
FaaS Meets Java EE: Developing Cloud Native Applications at SpeedFaaS Meets Java EE: Developing Cloud Native Applications at Speed
FaaS Meets Java EE: Developing Cloud Native Applications at Speed
 
AltConf 2019: Server-Side Swift State of the Union
AltConf 2019:  Server-Side Swift State of the UnionAltConf 2019:  Server-Side Swift State of the Union
AltConf 2019: Server-Side Swift State of the Union
 
Server-side Swift with Swagger
Server-side Swift with SwaggerServer-side Swift with Swagger
Server-side Swift with Swagger
 
Node Summit 2018: Cloud Native Node.js
Node Summit 2018: Cloud Native Node.jsNode Summit 2018: Cloud Native Node.js
Node Summit 2018: Cloud Native Node.js
 
Index - BFFs vs GraphQL
Index - BFFs vs GraphQLIndex - BFFs vs GraphQL
Index - BFFs vs GraphQL
 
Swift Cloud Workshop - Swift Microservices
Swift Cloud Workshop - Swift MicroservicesSwift Cloud Workshop - Swift Microservices
Swift Cloud Workshop - Swift Microservices
 
Swift Summit 2017: Server Swift State of the Union
Swift Summit 2017: Server Swift State of the UnionSwift Summit 2017: Server Swift State of the Union
Swift Summit 2017: Server Swift State of the Union
 
IBM Cloud University: Build, Deploy and Scale Node.js Microservices
IBM Cloud University: Build, Deploy and Scale Node.js MicroservicesIBM Cloud University: Build, Deploy and Scale Node.js Microservices
IBM Cloud University: Build, Deploy and Scale Node.js Microservices
 
IBM Cloud University: Java, Node.js and Swift
IBM Cloud University: Java, Node.js and SwiftIBM Cloud University: Java, Node.js and Swift
IBM Cloud University: Java, Node.js and Swift
 
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
Node Interactive: Node.js Performance and Highly Scalable Micro-ServicesNode Interactive: Node.js Performance and Highly Scalable Micro-Services
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
 
FrenchKit 2017: Server(less) Swift
FrenchKit 2017: Server(less) SwiftFrenchKit 2017: Server(less) Swift
FrenchKit 2017: Server(less) Swift
 
AltConf 2017: Full Stack Swift in 30 Minutes
AltConf 2017: Full Stack Swift in 30 MinutesAltConf 2017: Full Stack Swift in 30 Minutes
AltConf 2017: Full Stack Swift in 30 Minutes
 
InterConnect: Server Side Swift for Java Developers
InterConnect:  Server Side Swift for Java DevelopersInterConnect:  Server Side Swift for Java Developers
InterConnect: Server Side Swift for Java Developers
 
InterConnect: Java, Node.js and Swift - Which, Why and When
InterConnect: Java, Node.js and Swift - Which, Why and WhenInterConnect: Java, Node.js and Swift - Which, Why and When
InterConnect: Java, Node.js and Swift - Which, Why and When
 
Playgrounds: Mobile + Swift = BFF
Playgrounds: Mobile + Swift = BFFPlaygrounds: Mobile + Swift = BFF
Playgrounds: Mobile + Swift = BFF
 
Swift Summit: Pushing the boundaries of Swift to the Server
Swift Summit: Pushing the boundaries of Swift to the ServerSwift Summit: Pushing the boundaries of Swift to the Server
Swift Summit: Pushing the boundaries of Swift to the Server
 
O'Reilly Software Architecture Conf: Cloud Economics
O'Reilly Software Architecture Conf: Cloud EconomicsO'Reilly Software Architecture Conf: Cloud Economics
O'Reilly Software Architecture Conf: Cloud Economics
 

Recently uploaded

Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 

Recently uploaded (20)

Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 

Swift Cloud Workshop - Codable, the key to Fullstack Swift

  • 1. Codable
 The key to Fullstack Swift Swift Cloud Workshop 3
 February 23rd, 2018 Chris Bailey
 (@Chris__Bailey)
  • 3. struct Profile { var name: String var photo: Data var dateOfBirth: Date } let profile = Profile(name: “Chris”, photo: image, dateOfBirth: Date(“06-06-1980”))
  • 4. struct Profile : Codable { var name: String var photo: Data var dateOfBirth: Date } let profile = Profile(name: “Chris”, photo: image, dateOfBirth: Date(“06-06-1980”))
  • 5. struct Profile : Codable { var name: String var photo: Data var dateOfBirth: Date } let profile = Profile(name: “Chris”, photo: image, dateOfBirth: Date(“06-06-1980”)) let encoder = JSONEncoder() let jsonData = try encoder.encode(profile)
  • 6. struct Profile : Codable { var name: String var photo: Data var dateOfBirth: Date } let profile = Profile(name: “Chris”, photo: image, dateOfBirth: Date(“06-06-1980”)) let encoder = JSONEncoder() let jsonData = try encoder.encode(profile) let decoder = JSONDecoder() let person = try decoder.decode(Profile.self, from: jsonData)
  • 8. { "name": "", "photo": "", "dateOfBirth": "" } { "name": "", "photo": "", "dateOfBirth": { "year": "month": "day": } } struct Profile { var name: String var photo: Data var dateOfBirth: Date } Swift var profile: [String : Any] Swift KITURA
  • 9. let profile = Profile(name: name, photo: photo)let json = JSON(data: data)
 guard json["name"].exists() else { response.status(.unprocessableEntity) response.send(json: JSON([ "error": "Missing reqired property `name`" ])) next() } guard let photo = Data(base64Encoded: photoString) else { response.status(.unprocessableEntity) response.send(json: JSON([ "error": "Type mismatch, `photo` expected to be Base64 encoded data" ])) next() } guard let name = json["name"].string else { response.status(.unprocessableEntity) response.send(json: JSON([ "error": "Type mismatch, `name` expected to be a String" ])) next() } guard json["photo"].exists() else { response.status(.unprocessableEntity) response.send(json: JSON([ "error": "Missing reqired property photo`" ])) next() } guard let photoString = json[“photo"].string else { response.status(.unprocessableEntity) response.send(json: JSON([ "error": "Type mismatch, `photo` expected to be a String" ])) next() }
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16. struct Profile { var name: String var photo: Data var dateOfBirth: Date } Swift
  • 17. struct Profile { var name: String var photo: Data var dateOfBirth: Date } Swift Swift KITURA
  • 18. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } Swift Swift KITURA
  • 19. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } Swift Swift struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } KITURA
  • 20. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } Swift Swift struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } let encoder = JSONEncoder() let data = try encoder.encode(profile) KITURA
  • 21. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } Swift Swift struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } let decoder = JSONDecoder() let person = try decoder.decode(Person.self, from: jsonData) KITURA
  • 22. { "name": "", "photo": "", "dateOfBirth": "" } { "name": "", "photo": "", "dateOfBirth": "" } struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } Swift Swift struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } KITURA
  • 23. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } Swift Swift struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } KITURA
  • 24. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } Swift Swift struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } KITURA
  • 25. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } Swift Swift struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } KITURA
  • 27. struct Profile { var name: String var photo: Data var dateOfBirth: Date }
  • 28. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date }
  • 29. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } extension Profile { enum CodingKeys: String, CodingKey { case name = "name"
 case photo = "photo" case dateOfBirth = "dateOfBirth" } }
 

  • 30. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } extension Profile { enum CodingKeys: String, CodingKey { case name = "name"
 case photo = "photo" case dateOfBirth = "dateOfBirth" } }
 
 extension Profile : Decodable { init(from decoder: Decoder) throws { } }
  • 31. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } extension Profile { enum CodingKeys: String, CodingKey { case name = "name"
 case photo = "photo" case dateOfBirth = "dateOfBirth" } }
 
 extension Profile : Decodable { init(from decoder: Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self)
 } }
  • 32. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } extension Profile { enum CodingKeys: String, CodingKey { case name = "name"
 case photo = "photo" case dateOfBirth = "dateOfBirth" } }
 
 extension Profile : Decodable { init(from decoder: Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self)
 name = try values.decode(String.self, forKey: .name) } }
  • 33. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } extension Profile { enum CodingKeys: String, CodingKey { case name = "name"
 case photo = "photo" case dateOfBirth = "dateOfBirth" } }
 
 extension Profile : Decodable { init(from decoder: Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self)
 name = try values.decode(String.self, forKey: .name) photo = try values.decode(Data.self, forKey: .photo) } }
  • 34. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } extension Profile { enum CodingKeys: String, CodingKey { case name = "name"
 case photo = "photo" case dateOfBirth = "dateOfBirth" } }
 
 extension Profile : Decodable { init(from decoder: Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self)
 name = try values.decode(String.self, forKey: .name) photo = try values.decode(Data.self, forKey: .photo) dateOfBirth = try values.decode(Date.self, forKey: .dateOfBirth) } }
  • 35. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } extension Profile { enum CodingKeys: String, CodingKey { case name = "name"
 case photo = "photo" case dateOfBirth = "dateOfBirth" } }
 
 extension Profile : Encodable { func encode(to encoder: Encoder) throws { } }
  • 36. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } extension Profile { enum CodingKeys: String, CodingKey { case name = "name"
 case photo = "photo" case dateOfBirth = "dateOfBirth" } }
 
 extension Profile : Encodable { func encode(to encoder: Encoder) throws { var container = try encoder.container(keyedBy: CodingKeys.self)
 } }
  • 37. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } extension Profile { enum CodingKeys: String, CodingKey { case name = "name"
 case photo = "photo" case dateOfBirth = "dateOfBirth" } }
 
 extension Profile : Encodable { func encode(to encoder: Encoder) throws { var container = try encoder.container(keyedBy: CodingKeys.self)
 try container.encode(name, forKey: .name) try container.encode(photo, forKey: .photo) try container.encode(dateOfBirth, forKey: .dateOfBirth) } }
  • 39. { "name": "John Doe", "photo": "jbbkj362", "dateOfBirth": "06-06-1980“ }
  • 40. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date }
  • 41. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } router.get("/profile", handler: getProfiles)
  • 42. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } router.get("/profile", handler: getProfiles) func getProfiles(request: RouterRequest, response: RouterResponse, next: () -> Void) -> Void { }
  • 43. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } router.get("/profile", handler: getProfiles) func getProfiles(request: RouterRequest, response: RouterResponse, next: () -> Void) -> Void { var profile = request.read(as: Profile.Type) }
  • 44. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } router.get("/profile", handler: getProfiles) func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void { }
  • 45. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } router.get("/profile", handler: getProfiles) func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void { ... respondWith(profiles, nil) }
  • 46. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } router.get("/profile", handler: getProfiles) router.post("/profile", handler: addProfile) func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void { ... respondWith(profiles, nil) }
  • 47. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } router.get("/profile", handler: getProfiles) router.post("/profile", handler: addProfile) func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void { ... respondWith(profiles, nil) } func addProfile(profile: Profile, respondWith: @escaping (Profile?, Error?) -> Void) -> Void { ... respondWith(profile, nil) }
  • 48. guard let backend = KituraKit(baseURL: "http://localhost:8080") else { print("Error creating KituraKit client") return } backend.get("/profile") { (profiles: [Profile]?, error: RequestError?) in ... } KITURAKIT
  • 51. { "name": "John Doe", "photo": "jbbkj362", "dateOfBirth": "06-06-1980“ }
  • 52. {"name": "John Doe","photo": "jbbkj362","dateOfBirth": "06-06-1980"}
  • 56. { name = "John Doe"}
  • 57. ? name = "John Doe"}
  • 58. ? name = "John Doe"#
  • 60. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } router.get("/profile", handler: getProfiles) func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void { ... respondWith(profiles, nil) }
  • 61. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } struct Query: QueryParams { var name: String } router.get("/profile", handler: getProfiles) func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void { ... respondWith(profiles, nil) }
  • 62. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } struct Query: QueryParams { var name: String } router.get("/profile", handler: getProfiles) func getProfiles( , respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void { ... respondWith(profiles, nil) }
  • 63. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } struct Query: QueryParams { var name: String } router.get("/profile", handler: getProfiles) func getProfiles(query: Query, respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void { ... respondWith(profiles, nil) }
  • 64. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } struct Query: QueryParams { var name: String } router.get("/profile", handler: getProfiles) func getProfiles(query: Query, respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void { ... respondWith(profiles , nil) }
  • 65. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } struct Query: QueryParams { var name: String } router.get("/profile", handler: getProfiles) func getProfiles(query: Query, respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void { ... respondWith(profiles.filter{ ($0.name == query.name), nil) }
  • 67. SELECT * from Profiles
  • 68. name,, photo, dateOfBirth, "John Doe", "jbbkj362", "06-06-1980",
  • 69. name,, photo, dateOfBirth "John Doe", "jbbkj362", "06-06-1980"
  • 72. struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date } router.get("/profile", handler: getProfiles) func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void { ... respondWith(profiles, nil) }
  • 73. struct Profile: Model { var name: String var photo: Data var dateOfBirth: Date } router.get("/profile", handler: getProfiles) func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void { ... respondWith(profiles, nil) }
  • 74. struct Profile: Model { var name: String var photo: Data var dateOfBirth: Date } router.get("/profile", handler: getProfiles) func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void { Profile.getAll() respondWith(profiles, nil) }
  • 75. struct Profile: Model { var name: String var photo: Data var dateOfBirth: Date } router.get("/profile", handler: getProfiles) func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void { Profile.getAll(respondWith) respondWith(profiles, nil) }
  • 76. struct Profile: Model { var name: String var photo: Data var dateOfBirth: Date } router.get("/profile", handler: getProfiles) func getProfiles(respondWith: @escaping ([Profile]?, Error?) -> Void) -> Void { Profile.getAll(respondWith) }
  • 77. struct Profile: Model { var name: String var photo: Data var dateOfBirth: Date } router.get("/profile", handler: getProfiles) func getProfiles(completion: @escaping ([Profile]?, Error?) -> Void) -> Void { Profile.getAll(completion) }
  • 78. SELECT * from Profiles
  • 79. SELECT * from Profiles
  • 80. SELECT * from Profiles WHERE name = “John Doe”
  • 81. struct Profile: Model { var name: String var photo: Data var dateOfBirth: Date } router.get("/profile", handler: getProfiles) func getProfiles(completion: @escaping ([Profile]?, Error?) -> Void) -> Void { Profile.getAll(completion) }
  • 82. struct Profile: Model { var name: String var photo: Data var dateOfBirth: Date } struct Query: QueryParams { var name: String } router.get("/profile", handler: getProfiles) func getProfiles(completion: @escaping ([Profile]?, Error?) -> Void) -> Void { Profile.getAll(completion) }
  • 83. struct Profile: Model { var name: String var photo: Data var dateOfBirth: Date } struct Query: QueryParams { var name: String } router.get("/profile", handler: getProfiles) func getProfiles(query: Query, completion: @escaping ([Profile]?, Error?) -> Void) -> Void { Profile.getAll(completion) }
  • 84. struct Profile: Model { var name: String var photo: Data var dateOfBirth: Date } struct Query: QueryParams { var name: String } router.get("/profile", handler: getProfiles) func getProfiles(query: Query, completion: @escaping ([Profile]?, Error?) -> Void) -> Void { Profile.getAll( completion) }
  • 85. struct Profile: Model { var name: String var photo: Data var dateOfBirth: Date } struct Query: QueryParams { var name: String } router.get("/profile", handler: getProfiles) func getProfiles(query: Query, completion: @escaping ([Profile]?, Error?) -> Void) -> Void { Profile.getAll(matching: query, completion) }