router.get("hello", String.parameter) { req in
let name = try req.parameters.next(String.self)
return "Hello, \(name)!"
}
The code above gives this compile error for router.get:
"Type ‘PathComponentsRepresentable’ does not conform to protocol ‘ExpressibleByStringLiteral’
How do we fix this. Thanks.
OK, I found the fix:
The book code is slightly different than the vapor generated code. Adding the return type (as the book does) will fix the issue.
router.get("hello", String.parameter) { req -> String in
2 Likes
@blakninja Thank you for sharing the solution - much appreciated! :]
0xtim
4
Well worked out! The reason is because the Swift compiler has trouble inferring complex expressions (even though it’s obvious for us!)