luckyframework / luckyframework/lucky

Create handler to mutate param key names

Open
#1,864 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.