Created
July 2, 2013 15:46
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
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