Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create handler to mutate param key names #1864

Open
jwoertink opened this issue Apr 11, 2024 · 0 comments
Open

Create handler to mutate param key names #1864

jwoertink opened this issue Apr 11, 2024 · 0 comments

Comments

@jwoertink
Copy link
Member

One common problem I've run in to working in the front-end world is that everything in javascript land is camelcased, but everything on the Crystal side is snakecased. What if we had a handler that you could enable and it would just auto-convert all param keys from firstName to first_name without you needing to change anything in either language?

$fetch("POST", {user: {firstName: "", lastName: ""}})

post "/users" do
  params.nested(:user).get("first_name")
end

One major thing to consider is if your POST body is heavy (i.e. uploading a file), you don't want to parse the request body a bunch of times.

Or maybe the get method can just say "find a key by this or the snake cased version of this". That would probably throw things off if you wanted to pass back first_name and firstName because of some weird legacy DB thing, but then I guess you just wouldn't enable this option.

This wouldn't be something turned on by default. Just an extra handler that if you wanted, you would add to your middleware stack Lucky::ParamTransformerHandler.new

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant