Can you give an example of Sanitizing Validator on Route


Please help me understand how sanitation works on routes with an example. thank you in advance :grin:


You have example in docs:

To make route validator also sanitize, read this:


This my route

Route.get('/number', 'TestConstroller.number').validator('Test')

This my validator

class Test {
  get validateAll () {
    return true
  get sanitizationRules () {
    return {
      value: 'to_int'
  get rules () {
    return {
      value: 'required|number'
  async fails (errorMessages) {
    return this.ctx.response.send(errorMessages)

This my controller

number({ request, response }) {
        return response.send({
            value: request.input('value'),
            type: (typeof request.input('value')

But i get error

        "message": "number validation failed on value",
        "field": "value",
        "validation": "number"

Why I don’t understand? :thinking::thinking:


Hey @KemBeka! :wave:

What’s the value of value?


The value, I use to send data through the request, with postman.


Of course :smiley:

But could you give us this value here?


I apologize for my fault. I’m understand how work sanitization . It turns out that sanitization does not work without representations.
Thank you all for your time. :joy::joy:


me interested in can be whether use sanitation without views?


Of course you can use sanitisation without view.

Let me rephrase my question.

Could you give us the request you are sending to your application?


I apologize for my fault. I figured it out. It was necessary to send through the body and not through the parameters. :rofl: