luckyframework / luckyframework/lucky
Create handler to mutate param key names
Nobody has claimed this yet.
- Dominant language
- Crystal
- Stars
- 2.7k
- Forks
- 172
- PR merge metrics
- No merged PRs in 30d
Description
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`
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the request middleware stack and the existing parameter parsing path; the issue proposes Lucky::ParamTransformerHandler.new but names no files or tests. Define how nested camelCase keys become snake_case, ensure request bodies are not parsed repeatedly, and verify the behavior is opt-in with coverage for the shown POST payload.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- crystal
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100