Rust

params

Module

Request parameters as JSON values: parsing query strings, form bodies and JSON bodies into Params.

Lists are arrays, maps with other keys are objects, and an empty JSON object stays an empty object.

Contents

use utopia_http::array_to_params;
Rust
pub fn array_to_params(array: &Array) -> Params

Converts a php_std::Array into params, with keys as strings, in order.

use utopia_http::decode_payload;
Rust
pub fn decode_payload(raw: &[u8]) -> Params

Decodes a JSON body into params.

A top-level object or array gives its members; objects whose keys are 0..n become arrays, and empty objects stay objects. Anything else (a scalar, an empty object, invalid JSON) gives no params.

use utopia_http::params_value;
Rust
pub fn params_value(params: &Params) -> Value

Params as a single JSON value: an array when the keys are 0..n (or there are none), an object otherwise.

use utopia_http::parse_query;
Rust
pub fn parse_query(input: &str) -> Params

Parses an application/x-www-form-urlencoded string (a query string or a form body) into params.

Bracketed names build nested values: a[]=x&a[]=y is the array ["x", "y"] and b[k]=v the object {"k": "v"}. Dots and spaces in names become underscores.

use utopia_http::parse_query_bytes;
Rust
pub fn parse_query_bytes(input: &[u8]) -> Params

Parses an application/x-www-form-urlencoded byte string into params, like parse_query.

use utopia_http::value_to_json;
Rust
pub fn value_to_json(value: &php_std::Value) -> Value

Converts a php_std::Value into a JSON value.

Lists become arrays and other arrays objects. Binary strings are decoded lossily (params hold UTF-8 only); non-finite floats become null.

Rust
pub type Params = Map<String, Value>

Decoded request parameters, by name.