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

Multiple Strings to a single Handler #2815

Open
Rich2 opened this issue Apr 30, 2024 · 4 comments
Open

Multiple Strings to a single Handler #2815

Rich2 opened this issue Apr 30, 2024 · 4 comments
Labels
💎 Bounty enhancement New feature or request

Comments

@Rich2
Copy link

Rich2 commented Apr 30, 2024

Request for a more succinct version of

val routes: Routes[Any, Response] = Routes(
    Method.GET / "" -> handHome,
    Method.GET / "index.html" -> handHome,
    Method.GET / "index.htm" -> handHome,
    Method.GET / "index" -> handHome

So personally my preference would be to for both a general solution to map from a collection of Strings to a Routes collection. But also a specific case as I imagine a good proportion of web sites will want to cover the standard Home page entry points.

I'm just starting to try out ZIO, so apologies, I don't think I can give a more detailed view that would be of value.

@Rich2 Rich2 added the enhancement New feature or request label Apr 30, 2024
@GrigoriiBerezin
Copy link
Contributor

GrigoriiBerezin commented May 6, 2024

I'm not sure that it is a good way to implement such method, but it can be represented like so:

val routes: Routes[Any, Response] = Routes(Method.GET / anyOf("", "index.html", "index.htm", "index") -> handSome)

Do we need method for that in library?

@kyri-petrou
Copy link
Collaborator

kyri-petrou commented May 7, 2024

I'm not sure that it is a good way to implement such method, but it can be represented like so:

val routes: Routes[Any, Response] = Routes(Method.GET / anyOf("", "index.html", "index.htm", "index") -> handSome)

Do we need method for that in library?

I like this approach, but I would perhaps consider using | or || instead?

Method.GET / ("" | "index.html" | "index.htm" | "index") -> handSome

@jdegoes
Copy link
Member

jdegoes commented Jun 5, 2024

The disadvantage of | is that it would have to be an extension method on a string. Whereas a method like anyOf requires no extensions. But either could work.

/bounty $75

Copy link

algora-pbc bot commented Jun 5, 2024

💎 $75 bounty • ZIO

Steps to solve:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💎 Bounty enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants