Skip to content

Instantly share code, notes, and snippets.

@searler
Created June 15, 2016 02:10
Show Gist options
  • Save searler/a28b39327d75596138443ad8cb8cc638 to your computer and use it in GitHub Desktop.
Save searler/a28b39327d75596138443ad8cb8cc638 to your computer and use it in GitHub Desktop.
Akka HTTP one way configuration command using case classes
def configure[T <: Config](implicit tag: ClassTag[T], convert:FromRequestUnmarshaller[T]) = path("app" / "configure" / tag.runtimeClass.getSimpleName) {
post {
entity(as[T]) { c =>
actorRef ! c
complete(StatusCodes.OK)
}
}
}
trait Config
case class Timeout(duration:Duration) extends Config
case class MaxLogSize(size:Int) extends Config
implicit val timeoutJson = jsonFormat1(Timeout)
implicit val maxLogSizeJson = jsonFormat1(MaxLogSize)
val route = configure(TimeOut) ~
configure(MaxLogSize)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment