因為業務需求,需要對Akka HTTP進行快速學習
什么是Akka HTTP?
Akka HTTP 模塊組在 akka-actor 和 akka-stream 的基礎上實現了全HTTP棧( 服務器- 及客戶- 端 )的功能
應用范圍?
不需要前端頁面,只需要通過REST/HTTP 提供接口連接的服務。
HTTP服務端的路由DSL?
路由DSL來描述HTTP"路由”和其相關處理
每個路由可以是一個或幾個不同的Directive層級組合而成,每個路由則專注處理一個類型的請求。
通過 路由DSL 生成的 Route 對象 必須進行對應的“綁定”才能開始處理不同
HTTP Routes 是什么?
Route 是Routing DSL的核心概念。
type Route = RequestContext => Future[routeResult]
requestContext.complete(...)
by calling complete a given response is sent to the client as reaction to the request. I
返回對響應的請求
The Routing Tree
val route =
a {
b {
c {
... // route 1
} ~
d {
... // route 2
} ~
... // route 3
} ~
e {
... // route 4
}
}
不同層級下route調用情況如下
Route 1 will only be reached if directives a, b and c all let the request pass through.
Route 2 will run if a and b pass, c rejects and d passes.
Route 3 will run if a and b pass, but c and d reject.