Group Group Group Group Group Group Group Group Group

About parameters.next method

#1

Question in the book:

// 1
router.get(“api”, “acronyms”, Acronym.parameter) {
req -> Future in
// 2
return try req.parameters.next(Acronym.self)
}

“Extract the acronym from the request using parameters. This computed property performs all the work necessary to get the acronym from the database.”

req.parameters.next(Acronym.self)

Why it can performs any process to grab data from database? How is the source code work on it?

#2

@0xtim Can you please help with this when you get a chance? Thank you - much appreciated! :]

#3

As well as the (very good) answer on StackOverflow - the part of the code you’re wanting to see is https://github.com/vapor/fluent/blob/3/Sources/Fluent/Model/Model.swift#L483

This is the magic that Vapor and Fluent use to convert the parameter to the ID and perform the DB lookup. Hope that helps!

#4

Thanks, I got the answer from SO.
Thanks to the help of @imike