This is the presentation I made at NSLondon meetup in may 2023.
Learn how to structure a full-stack mobile app using Swift and a Serverless REST API. The talk covers the fundamentals of serverless application based on APIGateway, Lambda and DynamoDB and provide a quick start guide for developing a Serverless REST API with Breeze, a Swift package developed specifically for this purpose.
5. DEMO APP
DATA MODEL
public struct Form: Codable {
public var key: String
public let name: String
public let fields: [Field]
public var createdAt: String?
public var updatedAt: String?
public init(key: String,
name: String,
fields: [Field],
createdAt: String? = nil,
updatedAt: String? = nil) {
self.key = key
self.name = name
self.fields = fields
self.createdAt = createdAt
self.updatedAt = updatedAt
}
enum CodingKeys: String, CodingKey {
case key = "formKey"
case name
case fields
case createdAt
case updatedAt
}
}
public struct Field: Codable {
public let question: String
public let answer: String?
public let choices: [String]?
public let selected: [String]?
public let type: FieldType
public init(question: String,
answer: String? = nil,
choices: [String]? = nil,
selected: [String]? = nil,
type: FieldType) {
self.question = question
self.answer = answer
self.choices = choices
self.selected = selected
self.type = type
}
}
public enum FieldType: String, Codable {
case text
case option
case multiOption
}
9. MOBILE & SERVERLESS
CODE ARCHITECTURE
BreezeLambdaAPIClient SharedModel
public struct Form: Codable {
public var key: String
public let name: String
public let fields: [Field]
public var createdAt: String?
public var updatedAt: String?
public init(key: String,
name: String,
fields: [Field],
createdAt: String? = nil,
updatedAt: String? = nil) {
self.key = key
self.name = name
self.fields = fields
self.createdAt = createdAt
self.updatedAt = updatedAt
}
enum CodingKeys: String, CodingKey {
case key = "formKey"
case name
case fields
case createdAt
case updatedAt
}
}
iOS - Swift
…
BreezeLambdaAPI BreezeDynamoDBService
SOTO
12. APP API SERVICE
BREEZE LAMBDA API CLIENT
struct Environment {
static func dev() throws -> APIClientEnv {
try APIClientEnv(session: URLSession.shared, baseURL: "<API GATEWAY BASE URL FROM SERVERLESS DEPLOY>")
}
}
extension FeedbackForm: KeyedCodable {}
struct Logger: APIClientLogging {
func log(request: URLRequest) {
print(request)
}
func log(data: Data, for response: URLResponse) {
print(response)
let value = String(data: data, encoding: .utf8) ?? ""
print(value)
}
}
13. LAMBDA CODE
ONE LINE OF CODE !!!
import Foundation
import BreezeLambdaAPI
import BreezeDynamoDBService
import SharedModel
extension Form: BreezeCodable { }
BreezeLambdaAPI<Form>.main()
public protocol BreezeCodable: Codable {
var key: String { get set }
var createdAt: String? { get set }
var updatedAt: String? { get set }
}
26. BREEZE WORKFLOW
STEP BY STEP WORKFLOW
▸ Git Clone https://github.com/swift-sprinter/Breeze
▸ Copy Breeze.yml con
fi
g from the README
▸ Add the Authorizer to the con
fi
g if you want to secure the API!!!
▸ Adjust the con
fi
guration
▸ Generate the code and customise the data model
▸ Build the Lambdas
▸ Deploy the Serverless
▸ Implement your app using the BreezeLambdaAPIClient
28. WHY SERVERLESS? WHY SWIFT? WHY BREEZE?
▸ Scalability
▸ Reduced Operational Overhead
▸ Pay per use
▸ Faster Time to market
▸ Easy Integration
WHY SERVERLESS?
29. WHY SERVERLESS? WHY SWIFT? WHY BREEZE?
▸ iOS Developers ❤ it!
▸ No need to learn a new language
▸ Modern and performant language
▸ Safe
▸ Expressive
▸ Fast
WHY SWIFT?
30. ▸ Quick Start!
▸ Project setup
▸ Build
▸ Deploy
▸ Full control
▸ Adaptable
▸ Open Source
WHY SERVERLESS? WHY SWIFT? WHY BREEZE?
WHY BREEZE?