Skip to content

Instantly share code, notes, and snippets.

@jjn1056
Last active October 8, 2021 15:12
Show Gist options
  • Save jjn1056/5a5dc402362360e1cde92e372ea4e511 to your computer and use it in GitHub Desktop.
Save jjn1056/5a5dc402362360e1cde92e372ea4e511 to your computer and use it in GitHub Desktop.
{
name => 'John',
age => '52',
address => {
street => "15604 Harry Lind Road",
zip => "78621",
},
email => ['[email protected]', '[email protected]'],
credit_cards: [
{ number => '245345345345345', exp => '2024-01-01' },
{ number => '666677777888878', exp => '2030-01-01' },
],
}
my $body = $c->req->body_params->strong(
'name',
'age',
'pref' => +{}, # empty hashref means we allow anything under this (here be Dragons...)
'address' => ['street', 'zip'], # allow address.street / address.zip
+{'email' => []}, # no keys, only values, ie email[0] = '...', email[1] = '...'
+{'credit_cards' => ['number', 'exp']},
);
# $body->all / etc # various ways to get a hash from
# ->body_params->whitelisted_keys('_add', '_delete') # Allow these keys anywhere anytime
# ->body_param->max_array_length(1000) # set the max number of items in an array allowed
# ->body_param->namespace('person') # start at 'person' (ie person.name => name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment