Building REST APIs
Grails makes APIs simple with response formats and JSON views.
class BookRestController {
static responseFormats = ['json','xml']
def index() { respond Book.list() }
def save() {
def b = new Book(request.JSON)
if (b.save()) respond b, [status:201] else respond b.errors, [status:422]
}
}
Versioning
Common pattern: include version in URL (e.g. /api/v1/books) or use header-based versioning.