An interface used to implement a validator for a JSON body that is part of a request.
interface UserLoginJsonSchema extends ApiXRequestInputSchema { readonly username: string; readonly password: string;}// a simple object to validate the username and password of a login endpoint.class UserLoginHttpBodyValidator implements ApiXHttpBodyValidator<UserLoginJsonSchema> { isValid(body: UserLoginJsonSchema): boolean { const usernameRegex = /^[a-zA-Z0-9]{5,12}$/; const passwordRegex = /^[a-zA-Z0-9@_.*&$!()-]{8,20}$/; return this.isString(body.username) && usernameRegex.test(body.username) && this.isString(body.password) && passwordRegex.test(body.password); } isString(str: unknown): boolean { return typeof str === 'string'; }} Copy
interface UserLoginJsonSchema extends ApiXRequestInputSchema { readonly username: string; readonly password: string;}// a simple object to validate the username and password of a login endpoint.class UserLoginHttpBodyValidator implements ApiXHttpBodyValidator<UserLoginJsonSchema> { isValid(body: UserLoginJsonSchema): boolean { const usernameRegex = /^[a-zA-Z0-9]{5,12}$/; const passwordRegex = /^[a-zA-Z0-9@_.*&$!()-]{8,20}$/; return this.isString(body.username) && usernameRegex.test(body.username) && this.isString(body.password) && passwordRegex.test(body.password); } isString(str: unknown): boolean { return typeof str === 'string'; }}
ApiXMethod#jsonBodyValidator
Determines if the HTTP body is valid.
The body to be validated.
A boolean value that determines whether the HTTP Body is valid.
An interface used to implement a validator for a JSON body that is part of a request.
Example
See
ApiXMethod#jsonBodyValidator