Akka:Http:ParameterDirectives
lastmod 2026-11-10created 2020-09-213 edits
ParameterDirectives는 Akka HTTP 라우팅 DSL 에서 URL 쿼리 매개변수를 추출하는 디렉티브 모음이다. parameter 와 parameters 로 매개변수 이름을 지정하면 그 값을 내부 라우트에 넘겨 주며 이름 뒤에 .as[Int] 로 형 변환, .? 로 선택 매개변수, ? 기본값 으로 기본값 지정, .* 로 반복 매개변수를 표현한다. 필수 매개변수가 없으면 자동으로 거부(rejection)가 발생해 400 응답으로 처리된다.
Optional parameter with default value
val route =
parameters('color, 'backgroundColor ? "white") { (color, backgroundColor) =>
complete(s"The color is '$color' and the background is '$backgroundColor'")
}