I am using Insomnia as the API Client, also tried Postman… I am getting a 422 error
{
“reason”: “Unprocessable Entity”,
“error”: true
}
Not sure what I am missing,…
My routes.swift is:
import Vapor
func routes(_ app: Application) throws {
app.get { req async in
"It works!"
}
app.get("hello") { req async -> String in
"Hello, world!"
}
app.get("hello", "vapor") { req -> String in
return "Hello Vapor, oh and Hello Chuck!"
}
app.get("hello", ":name") { req -> String in
guard let name = req.parameters.get("name") else {
throw Abort(.internalServerError)
}
return "Hello, \(name)!"
}
app.post("info") { req -> String in
let data = try req.content.decode(InfoData.self)
return "Hello \(data.name)!"
}
}
struct InfoData: Content {
let name: String
}
Please advise
This is resolved, I was putting the parameters in as a query instead of the body…