Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 13:31
    joroKr21 synchronize #1478
  • 13:31

    joroKr21 on dispatcher-testing-apis

    Update finagle-http, finagle-st… Merge pull request #1479 from s… Stop magically converting Twitt… and 17 more (compare)

  • 12:55
    joroKr21 commented #1478
  • 06:05

    joroKr21 on master

    Update cats-effect to 3.3.12 Merge pull request #1489 from s… (compare)

  • 06:05
    joroKr21 closed #1489
  • 04:16
    scala-steward opened #1489
  • May 20 06:13

    joroKr21 on master

    Update circe-core, circe-generi… Merge pull request #1488 from s… (compare)

  • May 20 06:13
    joroKr21 closed #1488
  • May 20 04:35
    scala-steward opened #1488
  • May 19 13:42

    joroKr21 on master

    Update sbt-wartremover, wartrem… Merge pull request #1487 from s… (compare)

  • May 19 13:42
    joroKr21 closed #1487
  • May 19 13:15
    scala-steward opened #1487
  • May 13 22:27
    scala-steward opened #1486
  • May 12 03:16

    vkostyukov on validated-again

    (compare)

  • May 12 03:16

    vkostyukov on master

    Get rid of RequestItem; rework … (compare)

  • May 12 03:16
    vkostyukov closed #1471
  • May 12 00:28
    vkostyukov synchronize #1471
  • May 12 00:28

    vkostyukov on validated-again

    more fixes (compare)

  • May 12 00:17
    vkostyukov commented #1471
  • May 10 13:40
    joroKr21 closed #1485
Sergey Kolbasov
@sergeykolbasov
I'd say it's confusing for new comers and I hope we'll soon drop the finchx name and replace finch artefact with this one
Sergey Kolbasov
@sergeykolbasov

Hey everyone

0.32.1 is available for download, shipped for Scala 2.13 with the latest Finagle 20.3.0 and cats 2

yay
Bagus Jatikusuma
@BagusJatikusuma
congrats, great job for finagle/finch team and community
Georgi Krastev
@joroKr21
:tada:
Dino Fancellu
@fancellu

Are there any examples out there of Finch returning images, i.e. the best way? I see an example of Serving static content, but readAll doesn't exist. Any fully fleshed examples?

Thanks

For example, I tried this, and I get a partial image.
  val catpath = Paths.get(ClassLoader.getSystemResource("./cats.jpg").toURI)
  val reader = Reader.fromFile(catpath.toFile)

  val cat: Future[Buf] =Reader.readAllItems(reader).map(_.head)

  val image: Endpoint[IO, Buf] = get(imageadmin :: path[Int]) { id: Int =>
    cat.map(Ok)
  }
Dino Fancellu
@fancellu
Ah, I reckon my .head was chopping it off. Anyway, this works, I get the full cat picture back. But no doubt there are better ways
  val catpath = Paths.get(ClassLoader.getSystemResource("./cats.jpg").toURI)
  val bytes: Array[Byte] =Files.readAllBytes(catpath)
  val catbuff: Buf =ByteArray(bytes:_*)

  val image: Endpoint[IO, Buf] = get(imageadmin :: path[Int]) { id: Int =>
    Ok(catbuff)
  }.handle(exceptionToBadRequest)
Georgi Krastev
@joroKr21
I wonder if it's possible to combine finch and fs2-io for that. But I have no time to try it.
Dino Fancellu
@fancellu

I'm trying to return a 404 with a phrase that is not simple "Not Found"

This doesn't change the phrase

Output.failure(new Exception("Image not found"), Status.NotFound)

or

NotFound(new Exception("Image not found")

I get a 404 just fine. But I want the phrase to be as in the exception. Raw header is

HTTP/1.1 404 Not Found\r\nDate: Mon, 30 Mar 2020 11:51:40 GMT\r\nServer: Finch\r\nContent-Length: 0\r\n\r\n

Frederick Cai
@zhenwenc

@fancellu Me again 😄 You need to implement your own implicit Encoder[Exception], and ensure it is in scope when calling toService / toServiceAs on your endpoint(s)

See https://finagle.github.io/finch/cookbook.html#converting-errors-into-json

Dino Fancellu
@fancellu

I do

  implicit val encodeException: Encoder[Exception] = Encoder.instance(e =>
    Json.obj("exception" -> Json.fromString(e.getMessage)))

What would I need to do to get it to put the getMessage into the HTTP reason?

Currently it says

HTTP/1.1 404 Not Found

htch
@htch

Why does returning twitter's Future from endpoint with Endpoint[IO,?] type works? Using finchx 0.32.1

For example:

import cats.effect.IO
import com.eslgaming.services.platform.lokalisewebhook.domain.{Event, WebhookError}
import com.eslgaming.services.platform.lokalisewebhook.handler.WebhookEventHandler
import com.twitter.util.Future
import com.twitter.util.logging.Logging
import io.finch.{Endpoint, Output, Ok, NoContent}
//import io.finch.catsEffect._
import io.finch.circe._
import shapeless.HNil
import io.circe.Json
//import io.catbird.util.twitterFutureInstance

object LokaliseWebhookEndpoint extends Logging {

  def apply(ipRangeEndpoint: Endpoint[IO,HNil], webhookEventHandler: WebhookEventHandler): Endpoint[IO,Unit] =
    Endpoint[IO].post(Endpoint[IO].path("webhook") :: ipRangeEndpoint :: Endpoint[IO].jsonBody[Json]) { body: Json =>
      if (body == Json.arr(Json.fromString("ping"))) {
        Future.value(Ok(()))
      } else {
        val event = body.as[Event].getOrElse(throw new RuntimeException())
        webhookEventHandler.handleEvent(event) map {
          case Right(_) => NoContent[Unit]
          case Left(err) => {
            Output.failure(new RuntimeException(err.message), err.status)
          }
        }
      }
    }

}

webhookEventHandler.handleEvent returns a twitter Future

Sergey Kolbasov
@sergeykolbasov
@htch there is an implicit coversion of Twitter Future -> Anything with Async
it lives inside of ToAsync and is available only for method endpoints, such as get("foo") { ... }
Kenneth Monteiro
@ManiacViper
Hello
anyone can point me in the right direction for a finch refined error message
how do i get one in the contentResponse
for paramOption[NonEmptyString]("marketingsource") it returns a BadRequest for a empty string but no error message
these are my imports import io.finch.refined._ import io.circe.refined._ // needed import eu.timepit.refined.auto._ import eu.timepit.refined.types.string.NonEmptyString
KP
@kpei

Hey guys, is it possible to flatten up nested Endpoints?

Let's say I have something like

(param[Int]("foo")).map {
   foo: Int => new fooEndpoint(foo)
}

The return type is an Endpoint[Endpoint[SomeResponseClass]]

Sergey Kolbasov
@sergeykolbasov

Hi @ManiacViper

You should define custom Encode[Exception] implicit instance and provide it at the call of .toService. Default encoding of all the exceptons is a blank page

@kpei No, it's not possible as endpoint is not monadic, but applicative. What's your use case?
Dino Fancellu
@fancellu

Does anyone know if Finch supports web sockets? Or some Finagle based code?

I see https://github.com/finagle/finagle-websocket but that project is inactive. Thanks

Nicolas Rinaudo
@nrinaudo
This might be a silly question, but I see:
has this not been pushed to maven central, or is not hosted there anymore?
Dino Fancellu
@fancellu
Any examples of Finch handling file upload? Or Finagle? Thanks
Sergey Kolbasov
@sergeykolbasov
@nrinaudo Are you sure you're checking for finchx artefact? https://index.scala-lang.org/finagle/finch/finchx-core
Nicolas Rinaudo
@nrinaudo
Ah, I'm pretty sure I'm not, I didn't realise the name of the project had changed!
Sergey Kolbasov
@sergeykolbasov
@fancellu Finch doesn't support websockets
@nrinaudo it's a temporary thing, as we've two artifacts atm: with Future and F[_] (or finchx)
Nicolas Rinaudo
@nrinaudo
right. and the one with Future is not being updated anymore?
Sergey Kolbasov
@sergeykolbasov
Next release is going to end the deprecation cycle for Future one and finchx will be gone as well, so there will be only finch
Yeah
Nicolas Rinaudo
@nrinaudo
so if I want support for 2.13, later versions of circe, ... I need to move to finchx temporarily
correct?
Sergey Kolbasov
@sergeykolbasov
yes
Nicolas Rinaudo
@nrinaudo
Understood, thank you.
Dino Fancellu
@fancellu

I have some Option fields in my case class, when they are none the Json from Circe says null. e.g. "eventId":null

How do I tell it to simply emit nothing for that field? Thanks

megri
@megri
@fancellu implicit val printer = Printer.noSpaces.copy(dropNullValues = true)
Actually there's an object in the finch-circe package which should solve this: https://github.com/finagle/finch/blob/master/circe/src/main/scala/io/finch/circe/package.scala#L12-L16
Dino Fancellu
@fancellu

I can't get either to work. i.e. my options are coming back as null still

e.g.

  import io.finch.circe.dropNullValues._

val videoCanned: Endpoint[IO, Video] = get(videoadmin :: "canned") {
    Ok(Video(9999,"canned","url","link", description = "canned"))
  }

But the optional null fields still come back as :null

What am I doing wrong?

Thanks

Dino Fancellu
@fancellu

Ah, got it working, just had to be careful with imports

https://gist.github.com/fancellu/b145ed3a0a27c6a1c414c0d485a44d37

Dermot Haughey
@hderms
anyone know how I can test a finch endpoint in concert with a finagle filter in tests?
is that possible?
Sergey Kolbasov
@sergeykolbasov
@hderms you would need to convert endpoint to service, apply this service to filter and then send a Request in
Dermot Haughey
@hderms
thanks @sergeykolbasov I ended up doing that
I now regret depending on a finagle filter I wrote to guarantee any uncaught exceptions would be formatted the proper way in the response
Sergey Kolbasov
@sergeykolbasov
mm, finch guarantees that compiled endpoint (one that you get with .compile) wouldn't throw within F[_] context and you need to take care only of Either[Throwable, Response]