You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Propose a more intuitive and concise syntax for handling path parameters in the Hono Client (hc).
Current vs Proposed Syntax
Current Usage
// Current syntax requires explicit param mappingconstresponse=awaithc<AppType>('/api').users[':id'].$get({param: {id: '123'}})// Multiple parameters are verboseconstresponse=awaithc<AppType>('/api').users[':userId'].posts[':postId'].$get({param: {userId: '123',postId: '456'}})
Proposed Usage
// Direct value in path segmentconstresponse=awaithc<AppType>('/api').users['123'].$get()// Multiple parameters are cleanerconstresponse=awaithc<AppType>('/api').users['123'].posts['456'].$get()
Benefits
Improved Developer Experience
More intuitive API design
Less boilerplate code
Reduced chance of parameter mapping errors
Better Code Readability
Path structure directly reflects the URL
Clearer intention in the code
Easier to maintain and review
Type Safety
Maintains full TypeScript support
Parameter types can be inferred from the route definition
Implementation Considerations
Proxy Handler Updates
Modify the proxy to detect parameter values in path segments
Automatically generate the params object
Preserve existing functionality for backward compatibility
Type System
Enhance type definitions to support both styles
Ensure proper type inference for path parameters
Documentation
Update documentation to reflect the new syntax
Backward Compatibility
The current syntax would be maintained for backward compatibility, allowing gradual adoption of the new syntax.
Examples
REST API Calls
// Get userawaithc<AppType>('/api').users['123'].$get()// Create post for userawaithc<AppType>('/api').users['123'].posts.$post({json: {title: 'Hello'}})// Update specific postawaithc<AppType>('/api').users['123'].posts['456'].$put({json: {title: 'Updated'}})
Query Parameters
// Still supports query parametersawaithc<AppType>('/api').users['123'].$get({query: {include: 'posts'}})
WebSocket Connections
// WebSocket with path parametersconstws=hc<AppType>('/api').users['123'].live.$ws()
Discussion Points
Should we consider any additional syntax improvements?
Are there edge cases we need to address?
How should we handle validation of parameter values?
The text was updated successfully, but these errors were encountered:
What is the feature you are proposing?
🚀 Enhanced hono/client API: Simplified Path Parameters
Summary
Propose a more intuitive and concise syntax for handling path parameters in the Hono Client (hc).
Current vs Proposed Syntax
Current Usage
Proposed Usage
Benefits
Improved Developer Experience
Better Code Readability
Type Safety
Implementation Considerations
Proxy Handler Updates
Type System
Documentation
Backward Compatibility
The current syntax would be maintained for backward compatibility, allowing gradual adoption of the new syntax.
Examples
REST API Calls
Query Parameters
WebSocket Connections
Discussion Points
The text was updated successfully, but these errors were encountered: