Interface QueryParams


public interface QueryParams
Interface for accessing HTTP query parameters with type-safe getters.

QueryParams provides convenient methods for extracting query parameters from HTTP requests with automatic type conversion for common types like integers, booleans, and doubles.

Access: Available through RequestContext.queryParams() when processing HTTP requests in endpoint methods.

Type Safety: The typed getter methods (getInteger(java.lang.String), getBoolean(java.lang.String), etc.) handle conversion from string values to the requested type, returning Optional.empty() if the parameter is missing or cannot be converted.

Multiple Values: Query parameters can have multiple values (e.g., ?tag=java&tag=http). Use getAll(String) to retrieve all values for a parameter name.

Map Conversion: Use toMap() for a simple key-value map (first value only) or toMultiMap() to preserve all values for parameters that appear multiple times.

  • Method Details

    • getString

      Optional<String> getString(String key)
      Returns the value of the first parameter with the given key if it exists.
    • getInteger

      Optional<Integer> getInteger(String key)
      Returns the Integer value of the first parameter with the given key if it exists.
    • getLong

      Optional<Long> getLong(String key)
      Returns the Long value of the first parameter with the given key if it exists.
    • getBoolean

      Optional<Boolean> getBoolean(String key)
      Returns the Boolean value of the first parameter with the given key if it exists.
    • getDouble

      Optional<Double> getDouble(String key)
      Returns the Double value of the first parameter with the given key if it exists.
    • getAll

      List<String> getAll(String key)
      Returns the value of all parameters with the given key.
    • getAll

      <T> List<T> getAll(String key, Function<String,T> mapper)
      Returns the value of all parameters with the given key using mapper function.
    • toMap

      Map<String,String> toMap()
      Returns a key/value map of the parameters. Use the `toMultiMap()` method to return all parameters if keys may occur multiple times.
    • toMultiMap

      Map<String,List<String>> toMultiMap()
      Returns a `Map` of all parameters. Use the `toMap()` method to filter out entries with duplicated keys.