Query string validation in Fastify
What does the example of query string validation look in the Fastify documentation? Like this:
1
2
3
4
5
6
const schema = {
querystring: {
name: { type: 'string' },
excitement: { type: 'integer' }
}
}
What is the problem? It is a lie!
The correct way of defining the schema of query parameters in this case (two values: “name” and “excitement”). Looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const querySchema = {
schema: {
querystring: {
type: 'object',
properties: {
name: {
type: 'string'
},
excitement: {
type: 'integer'
},
}
}
}
}
Parsing machine learning logs with Ahana, a managed Presto service, and Cube, a headless BI solution

Check out my article published on the Cube.dev blog!
Additionally, if we want to make the name parameter mandatory, we add it to the array of required parameters:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const querySchema = {
schema: {
querystring: {
type: 'object',
properties: {
name: {
type: 'string'
},
excitement: {
type: 'integer'
},
}
required: ['name']
}
}
}
You may also like
Bartosz Mikulski
- Data/MLOps engineer by day
- DevRel/copywriter by night
- Python and data engineering trainer
- Conference speaker
- Contributed a chapter to the book "97 Things Every Data Engineer Should Know"
- Twitter: @mikulskibartosz