qs_adv
Types
pub type Config {
Config(fail_on_invalid: Bool, scheme: Scheme)
}
Constructors
-
Config(fail_on_invalid: Bool, scheme: Scheme)
pub type OneOrMany {
One(String)
Many(List(String))
}
Constructors
-
One(String)
-
Many(List(String))
Functions
pub fn default_config() -> Config
pub fn default_parse(
qs: String,
) -> Result(Dict(String, OneOrMany), String)
Parse a query string
Example
"?color=red&tags[]=large&tags[]=wool"
|> qs.default_parse
==
Ok(
dict.from_list(
[ #("color", One("red")), #("tags", Many(["large", "wool"])) ]
)
)
pub fn default_serialize(
query: Dict(String, OneOrMany),
) -> String
Serialize a query
Example
[ #("color", One("red")), #("tags", Many(["large", "wool"])) ]
|> qs.serialize
==
"?color=red&tags[]=large&tags[]=wool"
pub fn get_as_bool(
query: Dict(String, OneOrMany),
key: String,
) -> Result(Bool, String)
Attempt to get one value as a Bool. If the value is a list this fails. If the value cannot be parsed to a Bool this fails.
pub fn get_as_float(
query: Dict(String, OneOrMany),
key: String,
) -> Result(Float, String)
Attempt to get one value as an Float. If the value is a list this fail.
pub fn get_as_int(
query: Dict(String, OneOrMany),
key: String,
) -> Result(Int, String)
Attempt to get one value as an Int. If the value is a list this fails. If the value cannot be parsed to an Int this fails.
pub fn get_as_list(
query: Dict(String, OneOrMany),
key: String,
) -> List(String)
Get values from the query as a list of strings (regardless if one or many). If key is not present this defaults to an empty list.
pub fn get_as_list_of_bool(
query: Dict(String, OneOrMany),
key: String,
) -> Result(List(Bool), String)
Attempt to get values as a list of Bool.
pub fn get_as_list_of_float(
query: Dict(String, OneOrMany),
key: String,
) -> Result(List(Float), String)
Attempt to get values as a list of Float.
pub fn get_as_list_of_int(
query: Dict(String, OneOrMany),
key: String,
) -> Result(List(Int), String)
Attempt to get values as a list of Int.
pub fn get_as_string(
query: Dict(String, OneOrMany),
key: String,
) -> Result(String, String)
Attempt to get one value as a String. If the value is a list this fails.
pub fn has_key(
query: Dict(String, OneOrMany),
key: String,
) -> Bool
Tell if the query has the given key.
pub fn insert(
query: Dict(String, OneOrMany),
key: String,
value: OneOrMany,
) -> Dict(String, OneOrMany)
Insert value.
pub fn insert_list(
query: Dict(String, OneOrMany),
key: String,
values: List(String),
) -> Dict(String, OneOrMany)
Set a list of values in the query.
pub fn insert_one(
query: Dict(String, OneOrMany),
key: String,
value: String,
) -> Dict(String, OneOrMany)
Set a unique value in the query.
pub fn maybe_get_as_list(
query: Dict(String, OneOrMany),
key: String,
) -> Result(List(String), String)
Get values from the query as a list of strings. If key is not present this returns an Error.
pub fn merge(
a: Dict(String, OneOrMany),
b: Dict(String, OneOrMany),
) -> Dict(String, OneOrMany)
pub fn scheme_rails_like() -> Scheme
pub fn with_scheme(config: Config, scheme: Scheme) -> Config