SlideShare ist ein Scribd-Unternehmen logo
1 von 88
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Ähnlich wie Swift Cloud Workshop - Codable, the key to Fullstack Swift

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
 

Ähnlich wie Swift Cloud Workshop - Codable, the key to Fullstack Swift (11)

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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfhow-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfMehmet Akar
 
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesGraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesNeo4j
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfmbmh111980
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignNeo4j
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabbereGrabber
 
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...OnePlan Solutions
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...naitiksharma1124
 
What need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java DevelopersWhat need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java DevelopersEmilyJiang23
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024Shane Coughlan
 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfWSO2
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Henry Schreiner
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAShane Coughlan
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Andrea Goulet
 
Naer Toolbar Redesign - Usability Research Synthesis
Naer Toolbar Redesign - Usability Research SynthesisNaer Toolbar Redesign - Usability Research Synthesis
Naer Toolbar Redesign - Usability Research Synthesisparimabajra
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Soroosh Khodami
 
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024Primacy Infotech
 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)Max Lee
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfsteffenkarlsson2
 

Kürzlich hochgeladen (20)

how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfhow-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdf
 
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesGraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by Design
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
 
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
What need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java DevelopersWhat need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java Developers
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdf
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
 
Naer Toolbar Redesign - Usability Research Synthesis
Naer Toolbar Redesign - Usability Research SynthesisNaer Toolbar Redesign - Usability Research Synthesis
Naer Toolbar Redesign - Usability Research Synthesis
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
 
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
 
AI Hackathon.pptx
AI                        Hackathon.pptxAI                        Hackathon.pptx
AI Hackathon.pptx
 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
 

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) }