abstract class Crest::ParamsEncoder
- Crest::ParamsEncoder
- Reference
- Object
Overview
Custom serializers
You can build your custom encoder, if you like.
The value of params_encoder
can be any Crest::ParamsEncoder
object that responds to: #encode(Hash) #=> String
The encoder will affect both how Crest processes query strings and how it serializes POST bodies.
The default encoder is Crest::FlatParamsEncoder
.
Direct Known Subclasses
Defined in:
crest/params_encoder.crClass Method Summary
- .encode(params : Hash) : String
-
.flatten_params(object : JSON::Any, parent_key : String | Nil = nil) : Array(Tuple(String, Crest::ParamsValue))
Transform JSON::Any
object
into a flat array of{key, value}
.
Instance Method Summary
Class Method Detail
def self.flatten_params(object : JSON::Any, parent_key : String | Nil = nil) : Array(Tuple(String, Crest::ParamsValue))
#
Transform JSON::Any object
into a flat array of {key, value}
.
parent_key
— Should not be passed (used for recursion)
params = JSON.parse(%({"access": [{"name": "mapping", "speed": "fast"}, {"name": "any", "speed": "slow"}]}))
Crest::FlatParamsEncoder.flatten_params(params)
# => [{"access[][name]", "mapping"}, {"access[][speed]", "fast"}, {"access[][name]", "any"}, {"access[][speed]", "slow"}]
Crest::EnumeratedFlatParamsEncoder.flatten_params(params)
# => [{"access[1][name]", "mapping"}, {"access[1][speed]", "fast"}, {"access[2][name]", "any"}, {"access[2][speed]", "slow"}]