This section will show you how to add more routes in Vapor:
- Open the routes.swift file from Project Navigator on Xcode's left panel and add the following code to the line right before the closing brace at the bottom:
. . .
router.get("greet", String.parameter) { req -> String in // [1]
let guest = try req.parameters.next(String.self) // [2]
return "Hi \(guest), greetings! Thanks for visiting us." // [3]
}
. . .
- The preceding code does three things:
- Add a new route using greet as the first parameter from the path components and specifying the second parameter to be a string.
- Extract the guest string from the request's next item in its parameters list.
- Interpolate the guest string in the string returning to the client.
If you build and run your project again, you can see the following output by directing your...