Integration is a key piece of modern software development. Whether integrating with external vendors or providing APIs for front-end technologies like AngularJS or ReactJS, REST is a popular choice. This session will walk through how and why using the Grails framework to create a RESTful API is easy and efficient. Attendees should have a basic understanding of REST and experience with a web application framework like Grails.
4. @jennstrater#Devoxx #restwithgrails3
New in Grails 3
• Based on Spring Boot
• Switched to Gradle for build system
• Major structural changes
• configuration
• tests
• scripts directory
5. @jennstrater#Devoxx #restwithgrails3
Web API profile
• Introduced in Grails 3.0.5
• Removes Unnecessary Features
• no GSPs
• New Features
• Grails Command line support
• domain classes with resource annotation
• RESTful controllers
• json/gson views* (Grails 3.1+)
10. @jennstrater#Devoxx #restwithgrails3
The Task - Gr8Data
• Capture and display gender ratios at companies using Groovy
and related technology around the world
• Currently available at: http://jlstrater.github.io/gr8ladies-d3/
• Data stored in a json file with contributions via github pull
requests
• Demo for this talk: http://github.com/jlstrater/gr8data
32. @jennstrater#Devoxx #restwithgrails3
Default Media Types
• xml if not specified
• on mappings and controllers
• formats = ["json","xml"]
• extension
• /countries.xml
• /countries.json
• Requesting a format not included returns 406 Not Acceptable
43. @jennstrater#Devoxx #restwithgrails3
Version By Namespace
package gr8data.v1
class HelloController {
static namespace = "v1"
def index() {
render "Hello, World (v1)"
}
}
package gr8data.v2
class HelloController {
static namespace = "v2"
def index() {
render "Hello, World (v2)"
}
}
44. @jennstrater#Devoxx #restwithgrails3
Security
• Spring Security Rest Plugin by Álvaro Sánchez Mariscal
• Token based authentication
• Greach 2014Video
• Grails 2 only
• Spring Security Plugin for Grails 3
• OAuth for Spring Boot
• Screencast by Bobby Warner of Agile Orbit
45. @jennstrater#Devoxx #restwithgrails3
Conclusion
• Grails web-api profile streamlines API creation.
• Grails defaults support HTTP status codes, HTTP methods,
custom media types, custom response formats, and versioning
fairly easily.
• More exciting changes coming to the web-api profile with
Grails 3.1!
46. @jennstrater#Devoxx #restwithgrails3
To Learn More
• Restful Web Services in Grails 3 at Gr8Conf US
• YouTube / Slides
• Restful Grails 3 at SpringOne2GX by Jeff Brown
• YouTube / Slides
• Grails 3.X Update at SpringOne2GX by Graeme Rocher
• YouTube / Slides
• Grails Documentation
• REST