elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
10.45k stars 223 forks source link

Feature Request: Support Camel Case Access for Snake Case API Endpoints in Eden #525

Open DoK6n opened 7 months ago

DoK6n commented 7 months ago

What is the problem this feature would solve?

When using Eden for frontend development, we currently have to access snake case API endpoints in a bracket notation, like api['sign-in'].post. This is because the endpoints are defined in snake case, such as '/sign-in'. It would be greatly beneficial if Eden could automatically convert these snake case endpoints to camel case, allowing us to use a more JavaScript-friendly syntax like api.signIn.post.

What is the feature you are proposing to solve the problem?

For example

before:

const { data, status } = await api['emergency-info']['available-beds'].get()

after:

const { data, status } = await api.emergencyInfo.availableBeds.get()
// or
const { data, status } = await api['emergency-info']['available-beds'].get()

This feature would maintain the original snake case routing on the backend while providing a more convenient and idiomatic way to access these endpoints on the frontend. Is there a way to implement this functionality, keeping the API routes in snake case as they are?

What alternatives have you considered?

No response

kravetsone commented 2 months ago

Looks like useless runtime overhead

I guess you can implement it in third-party eden threaty-like implementation