Siva Kumar Siva Kumar - 2 months ago 8
Scala Question

found : akka.http.scaladsl.server.StandardRoute [error] required: scala.util.Try

I am new to Scala and to akka i am trying to publish endpoint. Following compilation error is occurring.

found: akka.http.scaladsl.server.StandardRoute
[error] required: scala.util.Try[Option[com.activegrid.entities.AuthSettings]] => (akka.http.scaladsl.server.RequestContext => scala.concurrent.Future[akka.http.scaladsl.server.RouteResult])


Case class

case class AuthSettings(authType:String,authLevel:String,scope:String);


Enpoint

pathPrefix("config") {
path("settings"/"auth") {
post {
entity(as[AuthSettings]) { authSettings =>
val save: Future[AuthSettings] = persistance.persistAuthSettings(authSettings)
onComplete(save) {
complete("To insert app settings")
}
}
}
}


persistAuthSettings definition

def persistAuthSettings(authSettings: AuthSettings) : Future[AuthSettings] = Future {
//Neo4j Operations
authSettings;


}

What is going wrong in my code?

Answer

onComplete extracts the value from the future, and requires a function which operates on this value:

onComplete(save) { appSettings =>
  complete("To insert app settings")
}