Main.scala 961 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import com.twitter.io.Buf
  2. import com.twitter.finagle.Http
  3. import com.twitter.finagle.http.{Request, Response}
  4. import com.twitter.finagle.Service
  5. import com.twitter.finagle.stack.nilStack
  6. import com.twitter.util.Await
  7. import cats.effect.IO
  8. import io.circe.Json
  9. import io.finch._
  10. import io.finch.circe._
  11. object Main extends App with Endpoint.Module[IO] {
  12. val helloWorld: Buf = Buf.Utf8("Hello, World!")
  13. val json: Endpoint[IO, Json] = get("json") {
  14. Ok(Json.obj("message" -> Json.fromString("Hello, World!")))
  15. }
  16. val plaintext: Endpoint[IO, Buf] = get("plaintext") {
  17. Ok(helloWorld)
  18. }
  19. val service: Service[Request, Response] =
  20. Bootstrap.configure(includeDateHeader = true, includeServerHeader = true)
  21. .serve[Application.Json](json)
  22. .serve[Text.Plain](plaintext)
  23. .toService
  24. Await.ready(
  25. Http.server
  26. .withCompressionLevel(0)
  27. .withStack(nilStack[Request, Response])
  28. .serve(":9000", service)
  29. )
  30. }