0

Im really new to this microservice world and was trying to learn from scratch. But for some reason not able to call a simple dependency.

Getting the error

object twitter is not a member of package com import com.twitter.finagle._

SBT file, Ive tried three ways

Trial 1

name := "microservicestest"

version := "0.1"

scalaVersion := "2.12.15"

libraryDependencies ++= Seq(
  "com.github.finagle" %% "finch-core" % "0.31.0",
  "com.github.finagle" %% "finch-circe" % "0.31.0",
  "io.circe" %% "circe-generic" % "0.9.0"
)

Trial 2 (puttting just the dependency line in here)

libraryDependencies += "com.twitter" %% "finagle-http" % "21.8.0"

Trial 3

libraryDependencies ++= Seq(
  "com.github.finagle" %% "finch-core" % "0.15.1"
)

Scala file

import io.finch._
import com.twitter.finagle.Http
import com.twitter.util.Await

object HelloWorld extends App {
  val api: Endpoint[String] = get("hello") { Ok("Hello, World!") }
  Await.ready(Http.server.serve(":8080", api.toServiceAs[Text.Plain]))
}
ss301
  • 514
  • 9
  • 22
  • Where do you get the error? Do you run an SBT command? – Gaël J Sep 20 '21 at 19:56
  • yes, while building it. – ss301 Sep 21 '21 at 05:27
  • Just one minor observation: your error states `object twitter is not a member of package com import com.twitter.finagle._`, and yet you do not actually have an import statement in your example that reads `import com.twitter.finagle._`. It seems that there's something missing here: can you post the entire output from when you run sbt? – FunProg Sep 21 '21 at 13:46
  • Yes I missed that line. Well I got a simple code working in sbt. Now im struggling in creating a bazel project. Will close this and create a new question. – ss301 Sep 21 '21 at 14:14
  • https://stackoverflow.com/questions/69270842/error-object-service-is-not-a-member-of-package-com-twitter-finagle-defining – ss301 Sep 21 '21 at 14:37

1 Answers1

0

SBT file

libraryDependencies += "com.twitter" %% "finagle-http" % "21.8.0"

Working simple code

import com.twitter.finagle.{Http, Service}
import com.twitter.finagle.http
import com.twitter.util.{Await, Future}

object HelloWorld extends App {
  val service = new Service[http.Request, http.Response] {
    def apply(req: http.Request): Future[http.Response] =
      Future.value(http.Response(req.version, http.Status.Ok))
  }
  val server = Http.serve(":8080", service)
  Await.ready(server)
}
ss301
  • 514
  • 9
  • 22