Basically the title. I want to know how to use url query parameters in Vapor 3. I can't seem to find anything in the docs on it.
e.g. /objects?fancy=true
, how do I access the fancy
parameter.
Basically the title. I want to know how to use url query parameters in Vapor 3. I can't seem to find anything in the docs on it.
e.g. /objects?fancy=true
, how do I access the fancy
parameter.
You can do something like e.g.:
guard let fancy = req.query[Bool.self, at: "fancy"] else {
throw Abort(.badRequest)
}
Or if it's optional you could do
if let qFancy = try? req.query.get(Bool.self, at: "fancy") {
fancy = qFancy
} else {
fancy = false
}