Created
July 2, 2015 08:03
-
-
Save kaning/27385be1ae2ccb60d759 to your computer and use it in GitHub Desktop.
Scalatra Action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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