Created
May 25, 2024 13:29
-
-
Save migueldeicaza/d85ef9fe0ac0a14162aeff512dd9072e to your computer and use it in GitHub Desktop.
Vapor version of
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// On my system, MacPro ARM | |
// .NET 8: 61,461 req/sec | |
// Swift 5.10: 64728 req/sec | |
// Port of https://gist.github.com/iSeiryu/c1b95242af000a11ea4710b79c2d6a53 | |
import Vapor | |
func routes(_ app: Application) throws { | |
app.get { req async in | |
"It works!" | |
} | |
app.get("hi") { req async -> String in | |
"hi" | |
} | |
app.post("send-money") { req async throws -> Receipt in | |
let r = try req.content.decode(SendMoneyRequest.self) | |
return Receipt(fromAccount: "\(r.from.firstName) \(r.from.lastName)", | |
toAccount: "\(r.to.firstName) \(r.to.lastName)", | |
toAddress: "\(r.to.address.street), \(r.to.address.city), \(r.to.address.state), \(r.to.address.zip)", | |
amount: r.amount, createdOn: Date()) | |
} | |
} | |
struct AccountHolder: Content { | |
let id: UUID | |
let firstName: String | |
let lastName: String | |
let address: Address | |
let email: String | |
} | |
struct Address: Content { | |
var street, city, zip: String | |
var state: State | |
} | |
enum State: String, Codable { | |
case CA | |
case NY | |
case WA | |
case TX | |
case FL | |
case IL | |
case PA | |
case OH | |
case GA | |
case MI | |
case NC | |
case NJ | |
case VA | |
} | |
struct SendMoneyRequest: Content { | |
var from, to: AccountHolder | |
var amount: Double | |
var sendOn: Date | |
} | |
struct Receipt: Content { | |
var fromAccount, toAccount, toAddress: String | |
var amount: Double | |
var createdOn: Date | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment