Skip to content
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

Improve the ergonomics of Endpoint#implement #2811

Closed
kitlangton opened this issue Apr 29, 2024 · 4 comments · Fixed by #2894
Closed

Improve the ergonomics of Endpoint#implement #2811

kitlangton opened this issue Apr 29, 2024 · 4 comments · Fixed by #2894
Labels

Comments

@kitlangton
Copy link
Member

Currently, implement must be passed a handler, which itself requires a function whose input matches the input of the endpoint. It's also necessary to manually ascribe a type to the handler's input parameter.

  val httpApp = Endpoint(Method.POST / "books").in[BookProps].out[Book]
    .implement(handler { (props: BookProps) => // <-- We must ascribe a type to the input parameter
      BookService.create(props)
    })

In ZIO land, we don't love manually ascribing types when they can be inferred from the context. Ideally, one could write the following:

  val httpApp = Endpoint(Method.POST / "books").in[BookProps].out[Book]
    .implement { props => BookService.create(props) }

As the Endpoint already knows its own input type, it can constrain the provided function to be of the right type. The user's IDE will know exactly what input is required, rather than forcing the user to provide a handler with a logically redundant + manual type ascription. Further, it would be great if implement built the handler internally, as it's just extra syntactic noise.

@kitlangton kitlangton added the enhancement New feature or request label Apr 29, 2024
@jdegoes
Copy link
Member

jdegoes commented Jun 5, 2024

/bounty $100

Copy link

algora-pbc bot commented Jun 5, 2024

💎 $100 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #2811 with your implementation plan
  2. Submit work: Create a pull request including /claim #2811 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
🟢 @987Nabil #2894

987Nabil added a commit to 987Nabil/zio-http that referenced this issue Jun 7, 2024
987Nabil added a commit to 987Nabil/zio-http that referenced this issue Jun 7, 2024
Copy link

algora-pbc bot commented Jun 7, 2024

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

987Nabil added a commit to 987Nabil/zio-http that referenced this issue Jun 7, 2024
987Nabil added a commit to 987Nabil/zio-http that referenced this issue Jun 7, 2024
987Nabil added a commit to 987Nabil/zio-http that referenced this issue Jun 7, 2024
987Nabil added a commit to 987Nabil/zio-http that referenced this issue Jun 7, 2024
987Nabil added a commit to 987Nabil/zio-http that referenced this issue Jun 7, 2024
jdegoes added a commit that referenced this issue Jun 9, 2024
Co-authored-by: John A. De Goes <john@degoes.net>
Copy link

algora-pbc bot commented Jun 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants