Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 22:23
    zarthross review_requested #398
  • 22:23
    zarthross opened #398
  • 22:22

    zarthross on Relax-Sync-Constraint

    Relaxing Sync constrainton RhoR… (compare)

  • 22:20

    zarthross on Relax-Sync-Constraint

    Relaxing Sync constrainton RhoR… (compare)

  • 21:58
    zarthross synchronize #373
  • 21:57

    bryce-anderson on gh-pages

    updated site (compare)

  • 21:57

    bryce-anderson on gh-pages

    updated site (compare)

  • 21:53

    zarthross on master

    Update scala-xml to 1.3.0 Merge pull request #394 from sc… (compare)

  • 21:53
    zarthross closed #394
  • 21:53

    zarthross on master

    Update sbt-mima-plugin to 0.7.0 Merge pull request #392 from sc… (compare)

  • 21:53
    zarthross closed #392
  • 21:53

    zarthross on master

    Update http4s-blaze-server, htt… Merge pull request #395 from sc… (compare)

  • 21:53
    zarthross closed #395
  • 21:52

    zarthross on master

    Update scala-collection-compat … Merge pull request #389 from sc… (compare)

  • 21:52
    zarthross closed #389
  • 21:52
    zarthross closed #390
  • 21:52
    zarthross commented #390
  • 03:03
    rossabaker closed #396
  • 03:03
    rossabaker commented #396
  • Mar 27 23:10

    bryce-anderson on gh-pages

    updated site (compare)

Guillaume Balaine
@Igosuki
And in AuthService :
val authenticated: AuthMiddleware[F, User] =
    AuthMiddleware.withFallThrough(authUser)
with
val authUser: Kleisli[OptionT[F, ?], Request[F], User]
have fun
Henry
@hygt
Hi, I'm new to rho (and http4s) and I'm trying to implement some custom error handling like this:
class Routes[F[+_]: Sync](service: FooService[F]) extends RhoRoutes[F] {

  private def handleError(t: Throwable): F[BaseResult[F]] = t match {
    case e: CustomError =>
      BadGateway(e)
    case _ =>
      InternalServerError(UnexpectedError)
  }

  GET / "api" +? param[Int]("id") |>> { id: Int =>
    service
      .getFoo(id)
      .flatMap { foo =>
        Ok(foo).widen[BaseResult[F]]
      }
      .handleErrorWith(handleError)
  }
}
I couldn't find a way to make it work without the widen
and of course, this messes up with the Swagger documentation
do I need some single ADT for all my API response types, including errors I want to encode?
I tried to return something like InternalServerError(someEmptyFooInstance) but it wouldn't compile either
Henry
@hygt
Ok... I moved the error handling to the service and it seems to work as expected
Magrahi haikal
@JMagrahiHaikal_twitter
Hello any Ideas on how to make a route deprecated please
Magrahi haikal
@JMagrahiHaikal_twitter
I discovered that deprecated feature not supported
0.20.0-M2 rho still using swagger 1.6 which don't support deprecation
Guillaume Balaine
@Igosuki
@hygt thanks for that, you actually solved my problem with scala 2.13, assigning every result in the Rho Kleislis to a F[BaseResult[F]] when the upper bound is F[A >:> Ok | BadRequest] for instance just works
now I can use foldF on EitherT and it all works
@hygt do you also have code that returns multiple response types and still works ?
in line 39 there is an example of how to return multiple response type
Guillaume Balaine
@Igosuki
ha! interesting
Ray Eldath
@Ray-Eldath
val authUser: Kleisli[IO, Request[IO], Either[String, User]] = Kleisli { req =>
  IO(Right(User("Bob", UUID.randomUUID())))
}

val onFailure: AuthedRoutes[String, IO] = Kleisli(req => OptionT.liftF(Forbidden(req.authInfo)))


val middleware = AuthMiddleware(authUser, onFailure)

object Auth extends AuthedContext[IO, User]

object BobRoutes extends RhoRoutes[IO] {
  GET +? param("foo", "bar") >>> Auth.auth |>> { (foo: String, user: User) =>
    Ok(s"Bob with id ${user.id}, foo $foo")
  }
}

val service = middleware.apply(Auth.toService(BobRoutes.toRoutes()))

This code is copied from AuthedContext.scala. But the Forbidden part is still "not found" after import bulk of things to make other part of code works... By the way, how to make service available for BlazeServerBuilder, or convert to HttpApp...?

Many thx!

Ray Eldath
@Ray-Eldath
And... is it possible to integrate rho with TSec...?
Guillaume Balaine
@Igosuki
Yes it is
Easily
  val jwtStatelessAuthenticator =
    JWTAuthenticator.pstateless.inHeader[F, User, HMACSHA256](
      signingKey = signingKey,
      settings = TSecJWTSettings(JWT_AUTH_HEADER, FiniteDuration(24L * 3600L, TimeUnit.SECONDS), None)
    )

  val authUser: Kleisli[OptionT[F, ?], Request[F], User] = Kleisli({ req =>
    if (userAuthentication) {
      jwtStatelessAuthenticator
        .extractAndValidate(req)
        .map(_.identity)
    } else {
      OptionT.pure[F](User.dummy)
    }
  })

  private[auth] val defaultNotAuthenticated: AuthedRequest[F, String] => OptionT[F, Response[F]] =
    req => OptionT.liftF(Forbidden(req.authInfo))

  val onAuthFailure: AuthedRoutes[String, F] = Kleisli(defaultNotAuthenticated)

  val authenticated: AuthMiddleware[F, User] =
    AuthMiddleware.withFallThrough(authUser)
Darren Gibson
@zarthross
Should be hitting maven central soon.
Guillaume Balaine
@Igosuki
nice
Tom Poczos
@TomPoczos
Hi, thought I'd ask if I'm going in a wrong direction. Refactoring a class that creates RhoRoutes so that it takes an F[_] instead of IO. Is RhoRoutes suitable for that? I guess it is, although all the example code / documentation uses IO. The reason I'm asking for is I have a route that returns different status codes based on some intermediate results and it works fine with IO but I can't get it to be of the required F[Result[...]] type with F[_]:ConcurrentEffect, instead it just defaults to Any As far as Intellij's shw implicits feature goes I can't see any difference. My ConcurrentEffect is being picked up instead of ioEffect which seems to be fine.
Guillaume Balaine
@Igosuki
@TomPoczos I have en entire App written with F
Yes with the latest Scala 2.12 and Http4s simply returning Ok or BadRequest won’t work anymore
Tom Poczos
@TomPoczos
@Igosuki thanks for the reply. Are you saying that it's a bug? Do you know of any workarounds or should I just give up on the idea to parametrize on F[_] instead of IO for now?
I mean, all over the documentation Ok & etc. are returned. Then again, all the documentation also appears to be using IO which works for me too
Christopher Davenport
@ChristopherDavenport
Have you tried F[+_]
Tom Poczos
@TomPoczos
@ChristopherDavenport doesn't work, just tried it. Anyway, I'm stuck with divergent implicits (confused myself a bit there, thought there's another error also occurring when trying to do this, but can't reproduce it any more), and for that at least I'm told there is an explanation at http4s/rho#292 ...not of much help since I can't get either of the proposed workarounds working. But at least I know it shouldn't be this way :)
Tom Poczos
@TomPoczos
@ChristopherDavenport thanks for your suggestion, together with some other changes (wrong cats import) it solved my issue
Darren Gibson
@zarthross
Rho 0.20.0 based on Http4s 0.21.0 has been released. (Should be rolling out to maven central now)
Eric Meisel
@etspaceman

Hello there. Is it possible to get this feature backported to the 0.19.x releases series? We are stuck using the 0.20.x Http4s series right now, and we're trying to build some functionality that depends on the content-type headers:

http4s/rho#359

Happy to open a PR against a branch if one is opened for me.

Eric Meisel
@etspaceman
I was able to open a PR against my own fork here to give an example: etspaceman/rho#1
If someone could help me out with a branch in the origin upstream, that would be helpful
Eric Meisel
@etspaceman

@zarthross is this something you can help me out with? We're using Rho internally but this is kind of a roadblock for us. We want to have a route support multiple content-types (e.g. json and proto), and we want to use the content-type header to control that. The Swagger document will unfortunately not work properly for this use case without that backport.

We are using 0.19.x because our team is still supporting Scala 2.11 at this time (and that cannot be changed until other vendor changes are completed).

Fredy Captuayo
@fredycaptuayo_gitlab

Hello, I updated ther dependencies in my project,
cats-core = 2.1.1
cats-effect = 2.1.2
rho-swagger = 0.20.0
http4s-blaze-server = 0.21.0

now, I have a problem in start the project, the error is

Could not find an instance of Applicative for [x]F[x]
[error]       server <- BlazeServerBuilder[F]
[error]              ^

Any suggestions to solve this error?, The code is this


import cats.effect.{ConcurrentEffect, ContextShift, ExitCode, IO, IOApp, Resource, Timer}
import co.yyyy.xxxxAPI
import org.http4s.server.Server
import org.http4s.server.blaze.BlazeServerBuilder

object Main extends IOApp {
  def run(args: List[String]): IO[ExitCode] =
    AppServer.create.use(_ => IO.never).as(ExitCode.Success)
}

object AppServerSwagger {
  def create[F[+_]: ConcurrentEffect: ContextShift: Timer]: Resource[F, Server[F]] =
    for {
      server <- BlazeServerBuilder[F]
        .withHttpApp(xxxxAPI[F].httpApi)
        .bindLocal(8085)
        .resource
    } yield server
}

Any error message

[error]  found   : cats.effect.Resource[[x]F[x],Nothing]
[error]  required: cats.effect.Resource[F,org.http4s.server.Server[F]]
[error]       config <- Resource.liftF(parser.decodePathF[F, DefaultConfig]("app"))
[error]              ^
Darren Gibson
@zarthross
@fredycaptuayo_gitlab It's because your ConcurrentEffect is defined using a F[+_]... its messing with the compiler inference. I suggest constructing your Rho parts in a separate function and passing it to the create so you can make create take a F[_] instead.
Darren Gibson
@zarthross
@etspaceman I'm open to a PR of the backport, here is a branch you can PR against: https://github.com/http4s/rho/tree/v0.19. I'll keep a lookout for your PR.
Eric Meisel
@etspaceman
Perfect, thanks Darren! I will submit that today
Eric Meisel
@etspaceman
@zarthross I have created the PR of the backport, sorry for the wait
Eric Meisel
@etspaceman
image.png
Hello there. Quick question. Are pathVars not supported like query params in terms of Enums? See above. Both use a StringParser based on an Enumeratum enum, but the path param comes through odd
this is on 0.19.1
implicit def producerTypeStringParser[F[_]]: StringParser[F, ProducerType] =
    new StringParser[F, ProducerType] {
      override def parse(
          s: String
        )(implicit F: Monad[F]
        ): ResultResponse[F, ProducerType] =
        try SuccessResponse(ProducerType.withName(s))
        catch {
          case _: NoSuchElementException =>
            FailureResponse.pure[F] {
              BadRequest.pure(s"Invalid ProducerType format: '$s'")
            }
        }
      override val typeTag: Option[TypeTag[ProducerType]] = Some(
        implicitly[TypeTag[ProducerType]]
      )
    }
This is my StringParser FWIW