Just started on the book and already hit a hurdle when adding a route with a parameter. I installed Vapor via Homebrew exactly as described in the book, all went well. However the example in the books is:
router.get("hello", String.parameter) { req -> String in
let name = try req.parameter(String.self)
return "Hello, \(name)!"
}
This does not compile, given the error that ‘Request’ has no member ‘parameter’. Even the code in documentation on the Vapor website for version 3.0 gives this error. However when I look at the version 2.0 documentation, it would assign the name variable like this:
let name = try req.parameters.next(String.self)
This works! But I’m using Vapor 3.0. When I type “vapor version” in terminal, it reports as 3.0.0, and under the dependencies in Xcode it’s using Vapor 3.0.0, and the code hint comments say to do it this way and not the way in the book.
This was very recently changed in Vapor 3.0. In earlier alpha and beta versions of Vapor 3.0, req.parameter(String.self) really was the correct call but shortly before the final release, the call was changed back to req.parameters.next(String.self). I assume the book will reflect this change soon as well.
For now, you’re good with using req.parameters.next(String.self) and don’t worry, you’re definitely using the correct version of Vapor, even if the documentation for 2.0 is strangely enough more relevant for this particular method than the current state of documentation for 3.0.
String.parameter is a Vapor 3 thing so looks like you’re conflating the two version. Take a look at the upgrade notes for how to convert and the newly updated tutorial for Vapor 4