Skip to content

Instantly share code, notes, and snippets.

@reikje
Created July 2, 2013 15:46
object ExampleRestApp {
@Api(value = "/", description = "Docs for our example controller")
@Path("/")
class RestController(statsReceiver: StatsReceiver = NullStatsReceiver) extends Controller(statsReceiver) {
get("/docs") { request =>
val content = Source.fromURL(getClass.getResource("/docs.html")).mkString
render.html(content).toFuture
}
get_user_id()
@ApiOperation(value = "Returns a user in json format.", notes = "Will only return a subset of the attributes.", responseClass = "java.lang.String", httpMethod = "GET")
@Path("user/{userId}")
@ApiErrors(Array(new ApiError(code = 404, reason = "No such user")))
def get_user_id(@ApiParam(name = "UserId", value = "A valid user id", required = true) env: Long = 0L) {
get("/user/:userId") { request =>
val userId: Long = request.routeParams.getOrElse("userId", "0").toLong
val user = someService.lookupUser(userId)
if (user == null) {
render.notFound.plain("").toFuture
} else {
render.body(user).header("Content-Type", "application/json").toFuture
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment