Route Parameters, Middleware, and Groups
Explore how to handle dynamic route parameters using the params object in AdonisJs. Understand how to attach middleware to routes to control access and execution. Learn to group routes with common prefixes using the group method, enabling cleaner and more manageable route definitions.
We'll cover the following...
We'll cover the following...
Route parameters
URL patterns in routes can contain parameters which are used to create dynamic routes.
'use strict'
class ConvertEmptyStringsToNull {
async handle ({ request }, next) {
if (Object.keys(request.body).length) {
request.body = Object.assign(
...Object.keys(request.body).map(key => ({
[key]: request.body[key] !== '' ? request.body[key] : null
}))
)
}
await next()
}
}
module.exports = ConvertEmptyStringsToNull
Press Run and wait for the output to be displayed in the Output tab. You may click on the link under the Run button and write anything in place of 1. We encourage you to try doing this.
Explanation
Take a look at ...