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

QueryParamDecoder instance for http4s #68

Closed
gabro opened this issue Nov 21, 2018 · 3 comments
Closed

QueryParamDecoder instance for http4s #68

gabro opened this issue Nov 21, 2018 · 3 comments

Comments

@gabro
Copy link
Contributor

gabro commented Nov 21, 2018

FUUIDVar from fuuid-http4s provides support for extracting path params, but there's no support for extracting query params.

It would essentially be something like

implicit val fuuidQueryParamDecoder: QueryParamDecoder[FUUID] =
  QueryParamDecoder.fromUnsafeCast(v => FUUID.fromString(v.value).right.get)("FUUID")

and use

object UserIdQueryParamMatcher extends QueryParamDecoderMatcher[FUUID]("userId")

val routes: HttpRoutes[F] = HttpRoutes.of[F]({
  case req @ GET -> Root / "get" :? UserIdQueryParamMatcher(userId) =>
    for {
      result <- controller.get(userId)
      res <- result.map(Ok(_)).getOrElse(NotFound())
    } yield res
})

@ChristopherDavenport if you agree this is useful, I can send a PR.

@ChristopherDavenport
Copy link
Collaborator

Sounds great! Are you on 0.1 or the 0.2 milestones?

If you target 0.1 I can merge it forward or only make it available in the new one. I'll leave that choice up to you.

Regardless it would make a great addition I believe. I imagine you are not alone in this desire.

@gabro
Copy link
Contributor Author

gabro commented Nov 21, 2018

I'm on 0.2.0-M2 currently, I'll add it to current master and I guess it can be added to the 0.1.0 series if there's demand.

@ChristopherDavenport
Copy link
Collaborator

Works for me! 😄

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

No branches or pull requests

2 participants