Skip to content

Instantly share code, notes, and snippets.

@dclucas
Last active August 29, 2015 14:21
Show Gist options
  • Save dclucas/87b30992246bcda73e98 to your computer and use it in GitHub Desktop.
Save dclucas/87b30992246bcda73e98 to your computer and use it in GitHub Desktop.
Sample DSL usage, for v 0.1 of the language
resource.definitions.Comment {
properties {
id {
type 'Integer'
description 'The comment id'
}
name {
type 'String'
description 'The comment name'
}
}
required 'id', 'name'
}
.paths."/comments" {
get { req, res ->
"comments.get"
}
post { req, res ->
def valResults = validate(req.body())
if (! valResults.isSuccess) {
return error.invalid valResults
}
if (exists(req.body())){
return error 429, "Resource already exist"
}
if (canPost(req)) {
return error.accessError "Sorry, but bots and spammers are not allowed to place comments."
}
return "comments.post"
}.document { docs ->
docs.description = "Description for comments.post"
docs
}
.skipAuth
.skipValidation
"/:id" {
get {req, res -> "comments/1.get"}
patch {req, res -> "comments/1.patch"}
.document { docs -> docs.operationId = "commentUpdate"; docs }
delete {req, res -> "comments/1.delete"}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment