Questions & Answers

How can I validate input data?

Deepkit HTTP
50 up-votes
Warning: The answer is generated by an artificial intelligence. It might not be correct.
To adjust rating, open the thread in Discord and click on the up/down vote button.

You can validate input data using runtime types and validation constraints from the @deepkit/type module. By specifying the types of parameters in your route handler or controller action, Deepkit automatically deserializes and validates the input data based on the defined types. You can also apply additional validation constraints using the validation type annotations provided by @deepkit/type. Here's an example:

import { Positive } from '@deepkit/type';

router.get('/user/:id', (id: number & Positive) => {
    // id is guaranteed to be a positive number
});