Get started quickly with Server-side Swift using Vapor and build your first Vapor web app in Swift!
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/890381-getting-started-with-server-side-swift-with-vapor
Get started quickly with Server-side Swift using Vapor and build your first Vapor web app in Swift!
great tutorial! Thank you
@ahspadafora Really glad you like it! Cheers! :]
Hey Tim. Why can’t i run app? How to fix it? Thanks Tim
@0xtim Can you please help with this when you get a chance? Thank you - much appreciated! :]
@lirpa21 what does swift run
show?
Sorry to bump this thread long after the long inactivity. Seemed like a better option than a comment on the video page.
I’m currently working through this and am trying to remake the TILApp in Vapor 4. Documentation is sparse and I’m getting stuck a lot. Now I have a problem which is probably minor I hope to get some pointers on.
I can’t for the life of me figure out how to make a call and return one item. The Vapor 4 basic template and documentation has helped me figure out the other routes and they work but not getting one item.
This is instrumental to a lot of work so I hope to get some pointers to keep going. Should be easy but I haven’t found examples and the documentation for Vapor 4 is sparse.
I’m refering to getting a single acronym in Chapter 11 Finishing Crud.
func getHandler(_req: Request) throws → Future {
return try req.parameters.next(Acronym.self)
}
Is what is described in the video for Vapor 3. Since - the syntax has changed and paramters is no longer available in the return clause.
I’ve been trying something like this to accomodate for the new syntax and make it elegant at the same time but won’t work and the Xcode beta is not helpful with errors
func getHandler(req: Request) throws → EventLoopFuture {
return Acronym.query(on req.db).SHOULDBESOMETHINGHERETOGETONEITEM?()
}
Dumbfounded. Hope this is seen and that someone has time to give a pointer. Stoked to learn some backend in the fave language!
Currently, for Vapor 4 you do
func getHandler(req: Request) throws -> EventLoopFuture<Acronym> {
Acronym.find(req.parameters.get("acronymID"), on: req.db).unwrap(or: Abort(.notFound))
}
I say currently because I think there’s some scope to improve that and there are some PRs and discussions happening about a way of solving it.
This project may help with your migration (though at the time of writing it may need updating to the latest betas)
Nice, thank you! This really helps me move past a major hurdle.
Interesting that the solution makes use of .find and the parameters syntax that they seem to want to move away from. Makes sense that it’s a wip as you say and maybe another solution will end up being the better one.
Thanks for the project link as well. Will definitely come in handy!
This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!