zio-http icon indicating copy to clipboard operation
zio-http copied to clipboard

Improve Routes DSL to support complex URI template patterns

Open limpid-kzonix opened this issue 1 year ago • 6 comments

Is your feature request related to a problem? Please describe. Extend capabilities of ZIO HTTP routes to cover use cases described in RFC 6570 - URI Template The issue that I came across is that the current ZIO Route DSL does not support defining complex use cases such as the following:

  • multiple path variables in the same path segment, e.g, http://example.com/people/{firstName}-{lastName}/SSN
  • extractor and literal within the same path segment, e.g http://example.com/people/{firstName}-some-literal/SSN or http://example.com/people/some-literal-{firstName}/SSN

Just for reference: https://docs.micronaut.io/latest/guide/#routing, Many other frameworks, including Spring, Quarkus, dotnet, actix-web, implement the URI template specification. But no single scala HTTP library is capable of that.

It would be nice to have the flexibility to define complex routes via Route DSL and Endpoint DSL to have a well-designed and documented API.

image

It seems that it is not possible right now to define a route that will follow Resource Oriented API with custom methods (more details here)

I remember that something similar was discussed in the zio-http discord channel - https://discord.com/channels/629491597070827530/819703129267372113/1162396036237623326 but without proper resolution.

Describe the solution you'd like I want to have DLS that provide an ability to define

  • multiple path variables in the same path segment:
POST / "virtual-machines" / string("vmId") / "instances" / PathCodec.combined(string("instanceId"), literal("_"), string("some_other_var"))
  • extractor and literal within the same path segments
POST / "virtual-machines" / string("vmId") / "instances" / PathCodec.combined(string("instanceId"), literal(":reboot"))

Describe alternatives you've considered

@erikvanoosten, probably you have some ideas, coz I remember discussion in discord about problem related to this issue.

Additional context https://softwaremill.community/t/paths-components-without-separator/317

limpid-kzonix avatar Feb 18 '24 18:02 limpid-kzonix

/bounty $750 for solution that does not impact performance and remains "zero allocation" and efficient, as well as backward compatible.

jdegoes avatar Jun 05 '24 02:06 jdegoes

💎 $750 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #2679 with your implementation plan
  2. Submit work: Create a pull request including /claim #2679 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio-http!

Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🔴 @bradovitt Jun 23, 2024, 2:25:03 AM WIP
🟡 @kyri-petrou Jun 30, 2024, 2:56:28 AM #2959
🟢 @987Nabil #2959

algora-pbc[bot] avatar Jun 05 '24 02:06 algora-pbc[bot]

/attempt #2679

Options

bradovitt avatar Jun 23 '24 02:06 bradovitt

@bradovitt: Reminder that in 7 days the bounty will become up for grabs, so please submit a pull request before then 🙏

algora-pbc[bot] avatar Jun 30 '24 02:06 algora-pbc[bot]

/attempt #2679

Algora profile Completed bounties Tech Active attempts Options
@kyri-petrou 18 ZIO bounties
Scala, Python,
Shell & more
Cancel attempt

kyri-petrou avatar Jun 30 '24 02:06 kyri-petrou

[!NOTE] The user @bradovitt is already attempting to complete issue #2679 and claim the bounty. We recommend checking in on @bradovitt's progress, and potentially collaborating, before starting a new solution.

algora-pbc[bot] avatar Jun 30 '24 02:06 algora-pbc[bot]

@kyri-petrou: Reminder that in 7 days the bounty will become up for grabs, so please submit a pull request before then 🙏

algora-pbc[bot] avatar Jul 07 '24 02:07 algora-pbc[bot]

💡 @987Nabil and @kyri-petrou submitted a pull request that claims the bounty. You can visit your bounty board to reward.

algora-pbc[bot] avatar Jul 13 '24 08:07 algora-pbc[bot]

🎉🎈 @987Nabil has been awarded $375! 🎈🎊

algora-pbc[bot] avatar Jul 15 '24 09:07 algora-pbc[bot]

🎉🎈 @kyri-petrou has been awarded $375! 🎈🎊

algora-pbc[bot] avatar Jul 15 '24 09:07 algora-pbc[bot]