Skip to content

Instantly share code, notes, and snippets.

@kaning
Created July 2, 2015 08:03
Show Gist options
  • Save kaning/27385be1ae2ccb60d759 to your computer and use it in GitHub Desktop.
Save kaning/27385be1ae2ccb60d759 to your computer and use it in GitHub Desktop.
Scalatra Action
val getUserById =
(apiOperation[User]("getUserById")
summary "Get a user by a given ID"
parameters pathParam[Int]("id").description("The id for the user to be retrieved"))
get("/:id", operation(getUserById)) {
val userID = params.getAs[Int]("id").getOrElse(halt(400))
val userData = Users.findUserByID(userID)
userData match {
case Seq(u) => u
case Seq() => halt(404)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment