@evlt/apix
    Preparing search index...

    Interface HttpBodyValidator<T>

    An interface used to implement a validator for a JSON body that is part of a request.

    interface UserLoginJsonSchema extends RequestInputSchema {
    readonly username: string;
    readonly password: string;
    }

    // a simple object to validate the username and password of a login endpoint.
    class UserLoginHttpBodyValidator implements HttpBodyValidator<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';
    }
    }
    interface HttpBodyValidator<T extends RequestInputSchema> {
        isValid(body: T): boolean;
    }

    Type Parameters

    Index

    Methods

    Methods