Giter VIP home page Giter VIP logo

Comments (5)

thetutlage avatar thetutlage commented on August 25, 2024 2

Code digging is a good exercise. But we have this mentioned in the docs too :)

Screenshot 2024-05-30 at 1 58 44 PM

from core.

aikrom avatar aikrom commented on August 25, 2024 1

So, we need to do a little research to understand why it's possible to check headers, cookies, and parameters, but not query strings.

We need to look at this first to understand how request.validateUsing(...) works. Then we find this part:

/**
 * Data to validate
 */
const data = validatorOptions.data || {
  ...this.#ctx.request.all(),
  ...this.#ctx.request.allFiles(),
  params: this.#ctx.request.params(),
  headers: this.#ctx.request.headers(),
  cookies: this.#ctx.request.cookiesList(),
}

And to further understand what request.all() does, we need to open this method and find out:

all(): Record<string, any> {
   return this.#requestData
}

And then we need to look around and find where (1, 2) the value for #requestData was set. For example:

updateBody(body: Record<string, any>) {
  this.#requestBody = body
  this.#requestData = { ...this.#requestBody, ...this.#requestQs }
}

And now we understand that when we use request.validateUsing(...) we can validate all the request data. Great!

P.S. If we don't like this approach, we can override request.validateUsing(...) to make it work the way we want.

from core.

aikrom avatar aikrom commented on August 25, 2024

Using validators inside controllers

from core.

kevinmelo avatar kevinmelo commented on August 25, 2024

Using validators inside controllers

i know i can use like that... as a mention and put the same link. But in adonis you can create a single validation that validate all the request (excluding the query string)

from core.

kevinmelo avatar kevinmelo commented on August 25, 2024

Hmm, then body and query string are the same thing for adonis, don't matter where they come from. Thanks.

At the end is better to override the class and make the query string separated.

from core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.