Reputation: 806
I am defining some paths but then i run into this error for the tilde ~ right before " pathPrefix(start)" . I am a bit new in Scala and so something do not click right away. thanks
not found:value ~
Is it because i need to define a function? If so why?
import
akka.http.scaladsl.marshallers.xml.ScalaXmlSupport.defaultNodeSeqMarshaller
import akka.http.scaladsl.server.{ HttpApp, Route }
import akka.http.scaladsl.model.StatusCodes
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import com.typesafe.config.ConfigFactory
import akka.event.Logging
import akka.http.scaladsl.model._
object ABC extends HttpApp with App {
implicit val actorSystem = ActorSystem()
implicit val matter = ActorMaterializer()
val start = "hello"
val Routing= {
path(start) {
redirect( Uri(start+ "/index.html"), StatusCodes.PermanentRedirect )
}
~
pathPrefix(start) {
content
}
}
val content =
{
get
{
path("html") {
getFromResource("src/html") }
}
}
}
Upvotes: 1
Views: 911
Reputation: 4308
If you're using Anorm from Play Framework, this other import
may help you:
import anorm._
Anorm has its own definitions of the ~
(tilde) function, e.g. parsing a SQL row into a Scala object:
The columns can also be specified by position, rather than name:
import anorm._ // Parsing column by name or position val parser = str("name") ~ float(3) /* third column as float */ map { case name ~ f => (name -> f) } val product: (String, Float) = SQL("SELECT * FROM prod WHERE id = {id}") .on("id" -> "p").as(parser.single)
Upvotes: 1
Reputation: 9023
Once you added the import as per @chunjef answer, also note that ~
is an infix operator, so it comes with all the "quirks" of it.
To sort out your routes, you can avoid placing the ~
in a new line
val Routing= {
path(start) {
redirect( Uri(start+ "/index.html"), StatusCodes.PermanentRedirect )
} ~
pathPrefix(start) {
content
}
}
or you can wrap the concatenated routes in brackets
val Routing= {
(path(start) {
redirect( Uri(start+ "/index.html"), StatusCodes.PermanentRedirect )
}
~
pathPrefix(start) {
content
})
}
Upvotes: 3
Reputation: 19517
Make sure you have the following import:
import akka.http.scaladsl.server.Directives._
Upvotes: 6