-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
[feature]: Add ability to assign routes to variables #664
Comments
Even more general way:
|
@bioform is this feature request mostly about rendering URLs? It seems like you could probably use a third-party URL template rendering library for this, something like:
Is there a reason you need this in the core Huma library instead? If you don't want an additional dependency you could write a quick/simple string replace implementation.
|
Thank you for the suggestion! The approach you outlined is valid and works well for simple use cases. However, I’m thinking of this feature more as syntactic sugar that could improve clarity and reduce boilerplate, especially when dealing with a larger set of routes. For example, with the proposed approach:
While functional, it may start to feel cluttered or disconnected as the number of routes grows. A typical setup might look like this:
In such cases, the route paths are managed separately from their related handlers, which can make the code harder to read and navigate, particularly for larger APIs. Embedding the ability to assign routes directly to variables as part of the Huma library would centralize route definitions and their usage. For example:
This approach keeps routes and their handlers closely coupled, improving maintainability and making the codebase more intuitive. While it’s possible to implement similar functionality with external libraries or custom code, having this natively within the Huma library would provide a more cohesive and streamlined experience for developers. |
BTW, to build an absolute route URL we need to know the server URL, like here:
Since the Huma already knows how to get this value - it can simplify things a bit. |
It would be good to have the ability to assign routes to variables...
Something like:
The text was updated successfully, but these errors were encountered: