简体   繁体   English

无法了解Akka HTTP中的路由

[英]Cannot understand routing in Akka HTTP

I have the following piece of code in Scala using Akka HTTP with Spray Routing 我在Scala中使用Akka HTTP和Spray Routing使用以下代码

import akka.http.scaladsl.server.Directives._

val geoip =
path(RemainingPath) {remaining =>

  val response = . . .

  complete(response)
}

But the I get the error message 但是我收到错误消息

[ERROR] FreeGeoIp.scala:45: error: missing parameter type
[ERROR]     path(RemainingPath) {remaining =>
[ERROR]                          ^
[ERROR] one error found

Where exactly is the parameter type supposed to go? 参数类型应该去哪儿?

The documentation on this is VERY poor, and according to the examples this code should work. 关于此的文档非常差,根据示例,此代码应该可以工作。

Problem solved. 问题解决了。 I had too many imports with wildcards. 我输入的通配符过多。 When I reduced the wildcards the problem went away. 当我减少通配符时,问题就消失了。 This set of imports seems to work. 这套进口似乎有效。

import akka.http.scaladsl.Http
import akka.http.scaladsl.model.HttpRequest
import akka.http.scaladsl.model.HttpResponse
import akka.http.scaladsl.model.Uri.apply
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport.sprayJsonUnmarshaller
import akka.http.scaladsl.marshalling.ToResponseMarshallable.apply
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.unmarshalling.Unmarshal

import akka.stream.scaladsl._

import scala.concurrent.Future

import spray.json._
import spray.json.DefaultJsonProtocol._

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM