Hello, everyone. I'm Vapor beginner.
I'm interested in Vapor 4 recently, started to make a toy project with it.
But having trouble with few things. Please help out if you have some ideas on it.
Here's what I want to create ;
-
Define
POST
routes with one parameters. -
Asyncronous job with 3rd party library.
-
Save to Database
func createHandler(_ req: Request) throws -> EventLoopFuture<CustomModel> {
// 1.
let param = try req.content.decode(ParamModel.self)
// 2. Asyncronous
ThirdPartyLibrary.request(with: param) { result in
// 3. How to save model and return EventLoopFuture
let saveModel = CustomModel(title: result.title,
description: result.description)
saveModel.save(on: req.db)
}
}
I found external API like this..
req.client.get(...)
req.client.post(...)
However, it is confused with the previous case.
Any idea how I can make this work?
Thank you.