1
votes

I am very new to Scala and tried writing an Spray API example using SBT for practice but getting below issue.

Issue with routing API ** Type Mismatch

 import spray.routing.SimpleRoutingApp 
 import akka.actor.ActorSystem 
 object ScalaBay extends App with SimpleRoutingApp { 
    implicit val actorSystem = ActorSystem() 
    startServer(interface = "localhost", port = 8080) { 
         get { path("hello") { 
            complete { "welcome" } 
               } 
         } 
    } 
 } 
  1. I have created a routing API using spray and Akka.
  2. once server starts with localhost address, once it gets path="hello" it should complete with some success message.
  3. But getting the error "Type mismatch, expected: (HNil) => routing.Route, actual: StandardRoute" while routing to after giving the path.

Please help me with how to resolve the issue.

1

1 Answers

0
votes

I think there's a place where you need to use a lambda syntax as the input is a function, not a value, just like the error suggests. HNil in Spray routing means you've defined no params or entities to be extracted from the route, so the function defined is defined from HNil, the empty HList type, but it's of the form HNil => routing.Route, so you need to use _ => route somewhere.

 import spray.routing.SimpleRoutingApp 
 import akka.actor.ActorSystem 
 object ScalaBay extends App with SimpleRoutingApp { 
    implicit val actorSystem = ActorSystem() 
    startServer(interface = "localhost", port = 8080) { 
         get { path("hello") { _ => 
            complete("welcome")
           } 
         } 
    } 
 }