scala - 为什么akka http可以使用方法路径而不扩展特征?
问题描述
通过 akka http 示例:https ://doc.akka.io/docs/akka-http/current/introduction.html#using-akka-http
object WebServer {
val route =
path("hello") {
get {
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Say hello to akka-http</h1>"))
}
}
路径是 trait PathDirectives 中定义的方法:
trait PathDirectives extends PathMatchers with ImplicitPathMatcherConstruction with ToNameReceptacleEnhancements {
def path[L](pm: PathMatcher[L]): Directive[L] = pathPrefix(pm ~ PathEnd)
那么WebServer不会使用方法路径,它必须扩展特征PathDirectives?为什么不需要?
谢谢!
解决方案
如果您使用正确的导入语句,则无需扩展任何内容。
import akka.http.scaladsl.server.Directives._
这带来了对象中定义的所有方法Directives
object Directives extends Directives
trait Directives extends RouteConcatenation
with BasicDirectives
with CacheConditionDirectives
with CookieDirectives
with DebuggingDirectives
with CodingDirectives
with ExecutionDirectives
with FileAndResourceDirectives
with FileUploadDirectives
with FormFieldDirectives
with FutureDirectives
with HeaderDirectives
with HostDirectives
with MarshallingDirectives
with MethodDirectives
with MiscDirectives
with ParameterDirectives
with TimeoutDirectives
with PathDirectives
with RangeDirectives
with RespondWithDirectives
with RouteDirectives
with SchemeDirectives
with SecurityDirectives
with WebSocketDirectives
with FramedEntityStreamingDirectives
其中也PathDirectives
包括
推荐阅读
- rust - 如何集成测试补品应用
- ubuntu - 在 Ubuntu 上 sudo ufw 导致 ssh 停止工作
- python - kafka-python:通过运行并发进程/脚本同时产生和使用来自同一主题的消息
- javascript - 我想收集所有用户的答案(选中的单选和复选框),看看用户是否选择了正确的答案。如果是这样,得分++
- ios - Google Vision Api Image 返回零
- python - 在赋值之前可能会引用局部变量“结果”
- .htaccess - 如何从我的 URL 中删除子文件夹?
- c# - Xamarin Forms 挂起数据加载
- python - 从给定整数中删除数字
- html - 通过选中复选框显示叠加菜单