Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 13 09:38
    joroKr21 synchronize #1516
  • Aug 13 09:36
    joroKr21 synchronize #1516
  • Aug 13 09:36
    joroKr21 synchronize #1516
  • Aug 13 09:19
    joroKr21 synchronize #1515
  • Aug 13 09:09
    joroKr21 synchronize #1515
  • Aug 13 09:09
    joroKr21 synchronize #1515
  • Aug 13 09:02
    joroKr21 synchronize #1516
  • Aug 13 09:01
    joroKr21 opened #1516
  • Aug 13 08:16
    joroKr21 opened #1515
  • Aug 12 17:02

    joroKr21 on master

    Update scalafmt-core to 3.5.9 Merge pull request #1514 from s… (compare)

  • Aug 12 17:02
    joroKr21 closed #1514
  • Aug 12 14:39
    scala-steward opened #1514
  • Aug 12 11:33
    joroKr21 commented #1098
  • Aug 12 11:32
    joroKr21 commented #1112
  • Aug 12 11:28
    joroKr21 commented #1407
  • Aug 12 11:23
    joroKr21 opened #1513
  • Aug 11 08:47

    joroKr21 on better-close-for-tw

    (compare)

  • Aug 11 08:47

    joroKr21 on master

    Clean up examples to not use to… Complete bootstrap rework Modi… Cleanup Bootstrap and 3 more (compare)

  • Aug 11 08:47
    joroKr21 closed #1481
  • Aug 11 08:26
    joroKr21 synchronize #1481
Dermot Haughey
@hderms
so I'm using finch fs2 support, in particular I have an endpoint like post("foo" :: binaryBodyStream[fs2.Stream]) { body: fs2.Stream[IO, Array[Byte]] => //etc... }
which compiles fine and seems to do what I want. However, I am having trouble getting a call to this endpoint to not 404.
Dermot Haughey
@hderms
in the documentation I saw: An [[Endpoint]] that matches chunked requests and lifts their content into a generic so I tried using Transfer-Encoding: chunked as a header, but I haven't had any luck
Dermot Haughey
@hderms
seems like withStreaming(true) was the missing link in this case
Chih
@Chih47911515_twitter
Hi all! I new to Finch! Tried to find some recent docs about polymorphic endpoints, but apparently, this is quite new and no docs were updated yet. I'm wondering does anyone has any working example to share on how to use Finch with ZIO? Thanks in advance!
1 reply
ComFreek
@ComFreek
If you process Options in your endpoint, what's the best practice to .getOrElse(return BadRequest(???)?
private def foo: Endpoint[IO, String] = get(path("debug")) {
  None.getOrElse(return BadRequest(???))
  Ok("test")
}
This does not typecheck since return will return the outer function (thus BadRequest(???) is expected to be of type Endpoint[IO, String])
But ideally, we would just return from the lambda passed to get(...)
ComFreek
@ComFreek
Other question: given a list of endpoints, can I automatically pretty-print it somehow? Such that the user gets a list of GET /post/list, POST /post/edit
Ryan Plessner
@rpless
for the first I example I tend to use fold. opt.fold[Output[String]](BadRequest(???))(_ => Ok("test")) note you do have provide the type parameter to the fold
as for the pretty-printing there as a toString that kinda does this, but you would have fiddle with the output to get the format you want
ComFreek
@ComFreek
@rpless Thanks. For the prettyprinting of endpoints, in my case I get
"(GET /help :+: (POST /archive :: build-light :+: (POST /archive :: build :+: (POST /fact :: add :: body :+: (GET /fact :: list :+: (GET /scroll :: list :+: (POST /scroll :: apply :: body :+: GET /debug :: situationtheory :: print)))))))"
which is not very helpful
even the parentheses look strangely unbalanced
e.g. GET /help is a single endpoint
ComFreek
@ComFreek
--> now posted on Finagle mailing list: https://groups.google.com/g/finaglers/c/LM5KzvSRpcI
Ryan Plessner
@rpless
the parens on that print out seem correct. basically every :+: introduces a set of parens so the endpoints wind up being fairly nested
re: your question in Finaglers auto generating developer docs isn't something that is supported at the moment. its a hard problem that we haven't solved. its one of the oldest issues on the repo finagle/finch#73
zanpakuto
@zanpakuto

I'm using finchx 0.32.1. I wrote below code, but unable to understand the reason for compilation error : "Cannot resolve overloaded method"

Can anyone please help me understand? Appreciate the help.

private val greetByName : Endpoint[IO, Json] = get(path("hello") :: paramOption("name")) = {
  Ok("Hello".asJson)
}
Ryan Plessner
@rpless
Hi @zanpakuto. I think the issue is that you are using paramOption which means the mapper is going to want an argument to the function you are using for mapping. something like this might be what you are looking for:
  private val greetByName: Endpoint[IO, Json] = get(path("hello") :: paramOption("name"))({ name: Option[String] =>
    Ok("Hello".asJson)
  })
zanpakuto
@zanpakuto
@rpless , thank you. The build is fine now.
Andrew Roberts
@aroberts
I have a POST endpoint consuming jsonBody and decoding via Circe, and I don’t seem to be able to catch the decoding error if it occurs- I want to be able to return a 400 response when bad json is submitted, but the circe DecodingFailure is wrapped in a finch-private CirceError case class. Is there a better approach to achieve this end?
Ryan Plessner
@rpless
@aroberts you should be able to access the Circe error even if its wrapped in Finch's private class. getCause should give you access to the underlying Circe error
Andrew Roberts
@aroberts
oh, interesting. I’m used to declarations shaped like class CirceError(cause: Error) extends Exception(cause) with NoStackTrace. My assumption was that CirceError.cause shadowed Exception.cause, but didn’t actually override it
Daave
@Daave_gitlab
Is there a way to get all params from a application/x-www-form-urlencoded in a Map
In play I can do it like so
def formHandler: Action[Map[String, Seq[String]]] = Action.async(parse.formUrlEncoded)
I can use param but I need to get all the params and they can be dynamic
Is there a way to do this?
Sergey Kolbasov
@sergeykolbasov
hmm, I think you need your own endpoint that is going to extract it for you. You could use something like root.map(request => request.getParams()) to get the Endpoint[F, List[Entry[String, String]]
Duncan Hills Coffee Company
@DuncanHills
can someone publish 0.32.1 to maven central?
0.31 is the latest version there...
kinda strange since that release was in march
ComFreek
@ComFreek
I copied the exception encoder from the user guide: https://finagle.github.io/finch/user-guide.html#errors
But it apparently doesn't take effect, I still get 500 internal server errors with empty body upon exceptions
Where do I have to define it?
ComFreek
@ComFreek
image.png
e.g. in this code (please ignore IntelliJ's broken graying), on runtime I get an exception and the println line is not even reached
ComFreek
@ComFreek
Not even this works:
import io.finch._
import cats.effect.IO
import com.twitter.finagle.Http
import com.twitter.io.Buf
import com.twitter.util.Await

object Test extends App with Endpoint.Module[IO] {
  implicit val encodeException: Encode.Text[Exception] =
    Encode.text((_, cs) => Buf.ByteArray.Owned("ERR!".getBytes(cs.name)))

  val api: Endpoint[IO, String] = get("hello") {
    throw new Exception("test")
    Ok("Hello, World!")
  }
  Await.ready(Http.server.serve(":8080", api.toServiceAs[Text.Plain]))
}
http://127.0.0.1:8080/hello does not output ERR! in the browser
Sergey Kolbasov
@sergeykolbasov

Hello @ComFreek

It's a bit trickier. That default encoder covers only "exceptions" inside of Output, i.e. BadRequest(new Exception("test"))

If you would like to cover all the exceptions, you need to set up filter on top of finagle's Service[Request, Response] or use middleware filters like here:
https://github.com/finagle/finch/blob/master/examples/src/main/scala/io/finch/middleware/Main.scala
shortly speaking in Finch we prefer to avoid exceptions as a mechanism and rather deal with errors as values, as it's much cleaner and easier to reason about
import io.finch._
import cats.effect.IO
import com.twitter.finagle.Http
import com.twitter.io.Buf
import com.twitter.util.Await

object Test extends App with Endpoint.Module[IO] {
  implicit val encodeException: Encode.Text[Exception] =
    Encode.text((_, cs) => Buf.ByteArray.Owned("ERR!".getBytes(cs.name)))

  val api: Endpoint[IO, String] = get("hello") {
    if (Random.nextBoolean()) {
      Ok("Hello, World!")
    } else {
      BadRequest(new Exception("oh no"))
    }
  }
  Await.ready(Http.server.serve(":8080", api.toServiceAs[Text.Plain]))
}
This should work
ComFreek
@ComFreek
@sergeykolbasov I understand your philosophy on values over exceptions, but for debugging receiving just a 500 Internal Server Error is utterly lacking.
I need those stack traces
Let me see if I can get the filter approach working