Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Feb 12 14:20
    sergeykolbasov commented #1204
  • Feb 12 00:10
    codecov-io commented #1204
  • Feb 12 00:10
    rpless review_requested #1204
  • Feb 12 00:10
    rpless review_requested #1204
  • Feb 12 00:10
    rpless commented #1204
  • Feb 12 00:03
    codecov-io commented #1204
  • Feb 12 00:03
    rpless synchronize #1204
  • Feb 11 03:46
    sergeykolbasov edited #1204
  • Feb 11 01:17
    rpless commented #1204
  • Feb 11 01:10
    rpless commented #1204
  • Feb 11 00:50
    rpless edited #1204
  • Feb 11 00:50
    rpless edited #1204
  • Feb 11 00:50
    rpless edited #1204
  • Feb 11 00:50
    rpless edited #1204
  • Feb 11 00:50
    rpless edited #1204
  • Feb 11 00:49
    codecov-io commented #1204
  • Feb 11 00:49
    rpless synchronize #1204
  • Feb 11 00:48
    codecov-io commented #1204
  • Feb 11 00:48
    rpless synchronize #1204
  • Feb 10 16:07
    rpless edited #1204
Prabhat Kashyap
@PKOfficial
This message was deleted
Sergey Kolbasov
@sergeykolbasov
@frgomes just return IO[Output[Something]] from your endpoint. At the moment you have a round-trip of IO -> Future -> IO
Richard Gomes
@frgomes
@sergeykolbasov : yeah... I suppose I'm missing some import of implicit conversions or something else, since the compiler complains that a Future is required.
[error] /home/rgomes/workspace/guided-repair-api/service/src/main/scala/Endpoints.scala:143:17: type mismatch;
[error]  found   : cats.effect.IO[io.finch.Output[api.model.ProductListResponse]]
[error]  required: scala.concurrent.Future[?]
[error]                 products //XXX .unsafeToFuture //FIXME: investigate if there's a way to avoid this call
I'm using these imports below:
  // These are magic imports which must survive IntelliJ attempts to "help us".
  // @formatter: off
  import cats.effect._
  import cats.implicits._
  import cats.syntax.apply._
  import io.circe.generic.auto._
  import io.finch._
  import io.finch.circe._
  // @formatter: on
Richard Gomes
@frgomes
My mistake. A for comprehension around the error line was imposing a Future. Fixing that fixes the entire endpoint.
@sergeykolbasov Thanks a lot :-)
Richard Gomes
@frgomes
Hello, I'm using filters in my endpoints.
I would like to "inject" a certain MyApp object into the Request when the request is authorized.
At the moment, the auth filter only blocks not authorized requests, but does not pass MyApp to compiled(req).
Any idea how this could be done, please?
trait Filters extends Whiteboard with StrictLogging {
  import io.finch._
  import cats.effect.IO
  import cats.implicits._
  import com.twitter.finagle.http.Status
  import com.twitter.finagle.http.Response

  def authorized(authorization: Option[String]): IO[MyApp] = tokenValidation.authorized(authorization)

  val auth: Endpoint.Compiled[IO] => Endpoint.Compiled[IO] =
    compiled => {
      Endpoint.Compiled[IO] { req =>
        authorized(req.authorization)
          .redeemWith(
            _ => (Trace.empty -> Right(Response(Status.Unauthorized))).pure[IO],
            //FIXME: should pass MyApp object into the request
            // See examples 2 and 3 of: https://finagle.github.io/finch/cookbook.html#defining-custom-endpoints
            myapp => IO(println(myapp)) *> compiled(req))
      }
    }
...
}
Sergey Kolbasov
@sergeykolbasov

@frgomes quick and dirty way would be to use Request#ctx: https://twitter.github.io/finatra/user-guide/http/filters.html#using-c-t-finagle-http-request-ctx or Context from Finagle that is roughly the same as ThreadLocal (but actually request local)

IMO, proper "functional" way would be to use a different monad instead and have an auth that would have a similar signature:

val auth: Endpoint.Compiled[ReaderT[IO, MyApp, *]] => Endpoint.Compiled[IO]

The idea here is to have underlying endpoints with effect ReaderT[IO, MyApp, *] that runs inside of Endpoint.Compiled[IO] where you have an access to request and can build the instance of MyApp

Having a ReaderT as your effect monad allows you to access environment MyApp whenever you feel like it
Richard Gomes
@frgomes
@sergeykolbasov : Thanks a lot. I'm going to try the "proper functional way" with Finch.
Richard Gomes
@frgomes
Integraton with Matrix: any idea why I see twitter/finagle from a Matrix client but I cannot see finagle/finch (this room)?
javier322
@javier322
Hello, how can I build asynchronous rest api with finch? ( I am new with this library)
Ryan Plessner
@rpless
Hi @javier322. If you are using any of the Endpoint Mappers that use Future or IO those are asynchronous. as for making an api RESTful that's really up to you to design the endpoints that way. Finch has all the building blocks for it. The Todo App Example might give you some ideas https://github.com/finagle/finch/blob/master/examples/src/main/scala/io/finch/todo/App.scala
javier322
@javier322
Thanks! @rpless
javier322
@javier322
Are there any example with future?
Sergey Kolbasov
@sergeykolbasov
It's not any different from the non-future examples, except that effect type of endpoint can't be Future and should be some lawful one like IO or Task
Finch will take care of the rest of the machinery
Dermot Haughey
@hderms
@sergeykolbasov doesn't scala/twitter future work do to ToAsync instances being defined for them?
we haven't had issues with it ourselves
Sergey Kolbasov
@sergeykolbasov
Exactly. Although, it's just to lift Future into F[_] : Async therefore you still can't have Endpoint[Future, A]
Dermot Haughey
@hderms
ah yeah
there definitely is a subtle distinction there worth calling out
Dermot Haughey
@hderms
anyone use ZIO with Finch?
trying to write an endpoint parameterized with ZIO and intellij is telling me it can't find an instance of Sync for ZIO. I added the interop-cats library which supposedly gives instances of various cats effect typeclasses for ZIO
Sergey Kolbasov
@sergeykolbasov
It does give it
Do you still have a problem with it?
Dermot Haughey
@hderms
ah i think it's a mismatch between what intellij is telling me and what compilation is telling me
I believe it just has to do with not using the appropriate type of partially applied ZIO type
since Endpoint.Module[F[_]] expects a single arguemnt type constructor
Richard Gomes
@frgomes

@hderms : Without willing to promote a flame war... but I've ditched IntelliJ from my workflow. To be honest, I always used IntelliJ just as a very clever text editor, using SBT and other external tools for compiling, testing, etc. So, if I there's another very clever text editor around (and there is!) I would not feel very much difference, really.

I'm using Emacs with scala-metals. The later employs LSP (Language Server Protocol) in order to talk to the Scala compiler.

This is the link for scala-metals. You will find configurations for several text editors and build tools there:
https://scalameta.org/metals/

Richard Gomes
@frgomes
If you never used Emacs... well... it's a steep learning curve. And there's a mountain of things to be configured and adapted, which is not necessarily a bad thing, since you can configure Emacs to fit your preferences for tools, your workflow, etc. If you are considering Emacs, I suggest you borrow a configuration file from someone else. This is mine:
https://github.com/frgomes/.emacs.d/tree/feature/0002-language-server-protocol
Notice: it's branch feature/0002-language-server-protocol
Dermot Haughey
@hderms
@frgomes I tried Emacs but vim keybindings are just wired into my brain at this point
and spacemacs was bloated and slow
Frederick Cai
@zhenwenc
@hderms Have you tried https://github.com/hlissner/doom-emacs with evil-mode(vim keybindings for emacs)? :wink:
Richard Gomes
@frgomes
@hderms : As @zhenwenc mentioned, Emacs can be configured to match Vim keybindings. However, I've never tried that. I have tried briefly doom-emacs but I've decided to copy the relevant niceties, adjusting to my existing workflow, leaving key bindings as usual Emacs.
Dermot Haughey
@hderms
thanks for the recommendation. I'll try that
Pierre Ricadat
@ghostdogpr
Hi everyone,
i was wondering if there was any plan for a new release? A lot of dependencies have been updated on master but the last release is from September.
Sergey Kolbasov
@sergeykolbasov

Hi @ghostdogpr

Is there something that is blocking you? We could land a release, but otherwise waiting for finagle-http 2.13 release that should happen soon, so we could release finch for 2.13

Pierre Ricadat
@ghostdogpr
@sergeykolbasov we wanted to create a module for Finch in a library called Caliban, but our dependency stack requires cats 2.0.0+. It’s not urgent or anything, just preventing us from adding this Finch module that would make it easier to use Caliban for Finch users.
Georgi Krastev
@joroKr21
cats 2 is binary compatible with cats 1 so this shouldn't be a problem
Pierre Ricadat
@ghostdogpr
Sorry I meant cats effect
It’s not because of Parallel I think
If I remember exactly, the issue was using the latest zio-interop-cats which is built with cats-effect 2.0.0 and not working properly if you use cats-effect 1.4.0
Pierre Ricadat
@ghostdogpr
[error] /Users/dermothaughey/projects/caliban/finch/src/main/scala/caliban/FinchHttpAdapter.scala:26:51: Symbol 'type cats.Parallel.Aux' is missing from the classpath.
Georgi Krastev
@joroKr21
Right, of course it's cats-effect, duh
The release says:
This is the first production release of cats-effect 2.x. It retains binary compatibility with 1.x, except Scala 2.11 and static forwarders for Java interop. See #566, #584 for a deeper discussion.
So I'm not sure if this then means that this release note is not quite true
Or was that Scala 2.11?