Last active
May 27, 2019 13:43
-
-
Save backslash-f/0f17656e65040d55d84b1a3c891df0bf to your computer and use it in GitHub Desktop.
Vapor, POST returning Future<SomeContent>
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
// `POST` receiving an `Request` and returning an `ReceiptValidation`. | |
func validate(_ request: Request) throws -> Future<ReceiptValidation> { | |
let promise = request.eventLoop.newPromise(ReceiptValidation.self) | |
DispatchQueue.global().async { | |
guard let receipt = try? request.content.decode(Receipt.self).wait() else { | |
promise.fail(error: Abort(HTTPResponseStatus.badRequest)) | |
return | |
} | |
let validation = ReceiptValidation(result: "Original receipt": \(receipt.data)") | |
promise.succeed(result: validation) | |
} | |
return promise.futureResult | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment