Questions & Answers

Can Deepkit automatically deserialize and validate input from HTTP requests?

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.

Yes, Deepkit can automatically deserialize and validate input from HTTP requests based on the defined types. This helps ensure that the input is correctly converted and validated before being processed.

import { MaxLength, MinLength } from '@deepkit/type';

interface User {
    username: string & MinLength<3> & MaxLength<20>;
    password: string & MinLength<4>;
}

router.post('/user/register', (user: HttpBody<User>) => {
    // Do something with the user
    // Return the result
    return true;
});