Validation
Lynx includes a validation middleware that allows you to validate incoming requests. You can validate the request JSON body, URL query, path parameters, and headers.
Manual Validation
The validator middleware takes a function that returns a boolean and an optional error message. If the function returns false
, the middleware will respond with a 400 status code and the error message.
After validation, the validated data is stored in the req.valid
table.
By default, the validator checks the JSON body. You can also validate the URL query, path parameters, or headers by using the optional first argument.
Validation targets: json
, query
, params
, headers
.
Validation with t
t
is a runtime type-checking library for Luau. The functions returned by t
can be used directly in the validator.
By using t
, you’ll get a more detailed error message when the validation fails.