Comments (5)
Code digging is a good exercise. But we have this mentioned in the docs too :)
![Screenshot 2024-05-30 at 1 58 44 PM](https://private-user-images.githubusercontent.com/1706381/335104019-0770f711-d535-413f-9e7b-d52a9c62833b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1NTg0MTMsIm5iZiI6MTcyNDU1ODExMywicGF0aCI6Ii8xNzA2MzgxLzMzNTEwNDAxOS0wNzcwZjcxMS1kNTM1LTQxM2YtOWU3Yi1kNTJhOWM2MjgzM2IucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgyNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MjVUMDM1NTEzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NjgzMjMzNzdjYjA3OGI0OTA4OGRiNmQ5N2NhZGNmMDVhYTBkYjBmNzQ0MjU5ODc4MGZiNGIwZmQwZmQ4ZTAxZCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.I4LiXVbB0-UfIUTy4GWhmo3Xm6EVPhfmJ1N7JzI3GpQ)
from core.
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.
Using validators inside controllers
from core.
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.
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)
- Hashing HOT 5
- Broken Installation of the Slim Starter Kit. HOT 6
- Bun support for ace add
- Install version 5 of Adonis in node 18 e 20 HOT 1
- Startup project error - mysql version
- The requested module 'node:module' does not provide an export named 'register' Error HOT 1
- Error: "Top-level await is not available in the configured target environment" HOT 1
- Undefined `@adonisjs/lucid/services/db` in commands HOT 2
- JAPA does not make correct API calls, unpredictably HOT 5
- Build Error HOT 5
- Env with special characters HOT 2
- ReferenceError: DateTime is not defined HOT 1
- Creating tests for commands cause "Error: ERR_PACKAGE_IMPORT_NOT_DEFINED #commands/greet" HOT 1
- Health checks cannot be performed as commands HOT 1
- Event object passed as object within object HOT 2
- Failed to load url inertia/app/ssr.tsx (resolved id: inertia/app/ssr.tsx). Does the file exist? HOT 2
- .env files for different node environments are not working HOT 2
- transmit.authorizeChannel not called HOT 1
- Do not use TypeScript features that require transformation (features that doesn't exist in JavaScript) like experimentalDecorators HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.