Function validateQuery

  • URL query decoder with type validation.

    typia.http.validateQuery() is a function decoding a query string or an URLSearchParams instance, with automatic type casting to the expected type. When property type be defined as boolean or number type, typia.http.validateQuery() will cast the value to the expected type when decoding.

    Also, after decoding, typia.http.validateQuery() performs type validation to the decoded value by combining with validate function. Therefore, when the decoded value is not following the T type, IValidation.IFailure would be returned. Otherwise, IValidation.ISuccess would be returned.

    By the way, as URL query is not enough to express complex data structures, typia.http.validateQuery() function has some limitations. If target type T is notfollowing those restrictions, compilation errors would be occured.

    1. Type T must be an object type
    2. Do not allow dynamic property
    3. Only boolean, bigint, number, string or their array types are allowed
    4. By the way, union type never be not allowed

    Type Parameters

    • T extends object

      Expected type of decoded value

    Parameters

    • input: string | URLSearchParams

      Query string or URLSearchParams instance

    Returns IValidation<Resolved<T>>

    Validation result with decoded query object

    Jeongho Nam - https://github.com/samchon