joroKr21 on dispatcher-testing-apis
Update finagle-http, finagle-st… Merge pull request #1479 from s… Stop magically converting Twitt… and 17 more (compare)
joroKr21 on master
Update cats-effect to 3.3.12 Merge pull request #1489 from s… (compare)
joroKr21 on master
Update circe-core, circe-generi… Merge pull request #1488 from s… (compare)
joroKr21 on master
Update sbt-wartremover, wartrem… Merge pull request #1487 from s… (compare)
vkostyukov on validated-again
vkostyukov on master
Get rid of RequestItem; rework … (compare)
vkostyukov on validated-again
more fixes (compare)
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)
}
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)
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
@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
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
ToAsync
and is available only for method endpoints, such as get("foo") { ... }
paramOption[NonEmptyString]("marketingsource")
it returns a BadRequest
for a empty string but no error message
import io.finch.refined._
import io.circe.refined._ // needed
import eu.timepit.refined.auto._
import eu.timepit.refined.types.string.NonEmptyString
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
Future
and F[_]
(or finchx)
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
Ah, got it working, just had to be careful with imports
https://gist.github.com/fancellu/b145ed3a0a27c6a1c414c0d485a44d37