class

Crest::FlatParamsEncoder

Inherits Crest::ParamsEncoder < Reference < Object

Class methods

flatten_params(object : Hash, parent_key : String | Nil = nil) : Array(Tuple(String, Crest::ParamsValue))

Transform deeply nested params containers into a flat array of {key, value}.

parent_key — Should not be passed (used for recursion)

Crest::FlatParamsEncoder.flatten_params({:key1 => {:key2 => "123"}})
# => [{"key1[key2]", "123"}]
Source
flatten_params(object : Array, parent_key : String | Nil = nil) : Array(Tuple(String, Crest::ParamsValue))

Transform deeply nested params containers into a flat array of {key, value}.

parent_key — Should not be passed (used for recursion)

Crest::FlatParamsEncoder.flatten_params({:key1 => {:arr => ["1", "2", "3"]}})
# => [{"key1[arr][]", "1"}, {"key1[arr][]", "2"}, {"key1[arr][]", "3"}]
Source

Instance methods

encode(params : Hash) : String

Converts the given params into a URI query string. Keys and values will converted to strings and appropriately escaped for the URI.

Crest::FlatParamsEncoder.encode({"a" => ["one", "two", "three"], "b" => true, "c" => "C", "d" => 1})
# => 'a[]=one&a[]=two&a[]=three&b=true&c=C&d=1'
Source