swifter
swifter copied to clipboard
is there a way to define routes using codables?
I'd like to have a route post body associated to a type. Not clear if I need to explicitly handle the body deserialize (i.e. using codable) and error handle myself or if I can define a route with that information included and the framework will reject invalid requests.
i.e
// define my type
struct User: Codable {
let name
let age
...
}
// define my route which should receive this type
server.POST['user'] = { requst in // request body should be a typed "User" type
or do I need to handle the serde dance in every route explicitly (leading to a lot of boiler plate):
i.e
// explicit handling with errors
{ request in
let decodedUser = .... decode request.body
if decodedUser is invalid return .error(....)
...
// handle valid user case
thanks