joroKr21 on master
Update scalafmt-core to 3.5.9 Merge pull request #1514 from s… (compare)
joroKr21 on better-close-for-tw
joroKr21 on master
Clean up examples to not use to… Complete bootstrap rework Modi… Cleanup Bootstrap and 3 more (compare)
private def foo: Endpoint[IO, String] = get(path("debug")) {
None.getOrElse(return BadRequest(???))
Ok("test")
}
return
will return the outer function (thus BadRequest(???)
is expected to be of type Endpoint[IO, String]
)
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)))))))"
GET /help
is a single endpoint
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)
}
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)
})
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?
def formHandler: Action[Map[String, Seq[String]]] = Action.async(parse.formUrlEncoded)
param
but I need to get all the params and they can be dynamic
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
Service[Request, Response]
or use middleware filters like here: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
*>
come from?