restful grails3
TRANSCRIPT
![Page 1: Restful Grails3](https://reader031.vdocuments.mx/reader031/viewer/2022021500/587143671a28ab55588b4eef/html5/thumbnails/1.jpg)
RESTful Grails 3
Jeff Scott Brown @jeffscottbrown
![Page 2: Restful Grails3](https://reader031.vdocuments.mx/reader031/viewer/2022021500/587143671a28ab55588b4eef/html5/thumbnails/2.jpg)
More at ociweb.com/grails
![Page 3: Restful Grails3](https://reader031.vdocuments.mx/reader031/viewer/2022021500/587143671a28ab55588b4eef/html5/thumbnails/3.jpg)
Copyright (c) 2015 Object Computing, Inc. All rights reserved.
WE ARE HIRING!
Groovy And Grails Project Work Grails 2 -> 3 Plugin Migrations Grails Plugin Development Expanding GORM’s Reach New Application Profiles Grails Core Development
![Page 4: Restful Grails3](https://reader031.vdocuments.mx/reader031/viewer/2022021500/587143671a28ab55588b4eef/html5/thumbnails/4.jpg)
Copyright (c) 2015 Object Computing, Inc. All rights reserved.
“REST is an architectural style consisting of a coordinated set of architectural constraints applied to components, connectors, and data elements, within a distributed hypermedia system.”
4
REST
— http://en.wikipedia.org/wiki/Representational_state_transfer
![Page 5: Restful Grails3](https://reader031.vdocuments.mx/reader031/viewer/2022021500/587143671a28ab55588b4eef/html5/thumbnails/5.jpg)
Copyright (c) 2015 Object Computing, Inc. All rights reserved.
Grails And REST
• Out Of The Box Support For Common Cases • URL Mappings • Data Binding • Domain Class Resources
• Customization Options • Renderers • Data Binding
5
![Page 6: Restful Grails3](https://reader031.vdocuments.mx/reader031/viewer/2022021500/587143671a28ab55588b4eef/html5/thumbnails/6.jpg)
Copyright (c) 2015 Object Computing, Inc. All rights reserved.
Standard Domain Class
6
![Page 7: Restful Grails3](https://reader031.vdocuments.mx/reader031/viewer/2022021500/587143671a28ab55588b4eef/html5/thumbnails/7.jpg)
Copyright (c) 2015 Object Computing, Inc. All rights reserved.
URL Mapping
7
![Page 8: Restful Grails3](https://reader031.vdocuments.mx/reader031/viewer/2022021500/587143671a28ab55588b4eef/html5/thumbnails/8.jpg)
Copyright (c) 2015 Object Computing, Inc. All rights reserved.
URL Mapping
8
Method URI ActionGET /people indexGET /people/create createPOST /people saveGET /people/{id} showGET /people/{id}/edit editPUT /people/{id} updateDELETE /people/{id} delete
![Page 9: Restful Grails3](https://reader031.vdocuments.mx/reader031/viewer/2022021500/587143671a28ab55588b4eef/html5/thumbnails/9.jpg)
Copyright (c) 2015 Object Computing, Inc. All rights reserved.
REST Requests
9
Get People: curl -H "Accept: application/json" -i http://localhost:8080/restconfdemo/people
Create Person: curl -i -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{"firstName":"Jake","lastName":"Brown","age":14}' http://localhost:8080/restconfdemo/people
Update Person: curl -i -X PUT -H "Content-Type: application/json" -H "Accept: application/json" -d '{“firstName":"Jacob"}' http://localhost:8080/restconfdemo/people/1
![Page 10: Restful Grails3](https://reader031.vdocuments.mx/reader031/viewer/2022021500/587143671a28ab55588b4eef/html5/thumbnails/10.jpg)
Copyright (c) 2015 Object Computing, Inc. All rights reserved.
Controller Action Allowed Methods
10
Don’t Need To Do This If Using allowedMethods.
![Page 11: Restful Grails3](https://reader031.vdocuments.mx/reader031/viewer/2022021500/587143671a28ab55588b4eef/html5/thumbnails/11.jpg)
Copyright (c) 2015 Object Computing, Inc. All rights reserved.
Data Binding And Command Objects
11
![Page 12: Restful Grails3](https://reader031.vdocuments.mx/reader031/viewer/2022021500/587143671a28ab55588b4eef/html5/thumbnails/12.jpg)
Copyright (c) 2015 Object Computing, Inc. All rights reserved.
Data Binding And Domain Class Command Objects
12
![Page 13: Restful Grails3](https://reader031.vdocuments.mx/reader031/viewer/2022021500/587143671a28ab55588b4eef/html5/thumbnails/13.jpg)
Copyright (c) 2015 Object Computing, Inc. All rights reserved.
Domain Class Resource Annotation
13
• Same URL Mappings • Same Controller Behavior • Same Data Binding • Same Rendering • Etc…
![Page 14: Restful Grails3](https://reader031.vdocuments.mx/reader031/viewer/2022021500/587143671a28ab55588b4eef/html5/thumbnails/14.jpg)
Copyright (c) 2015 Object Computing, Inc. All rights reserved.
Responding
14
Preferred
![Page 15: Restful Grails3](https://reader031.vdocuments.mx/reader031/viewer/2022021500/587143671a28ab55588b4eef/html5/thumbnails/15.jpg)
Copyright (c) 2015 Object Computing, Inc. All rights reserved.
Customizing The Default Renderers
15
curl -i http://localhost:8080/restconfdemo/people.json
[{“class":"demo.Person","id":1,"firstName":"Jake","lastName":"Brown"}, {“class":"demo.Person","id":2,"firstName":"Zack","lastName":"Brown"}, {"class":"demo.Person","id":3,"firstName":"Jeff","lastName":"Brown"}]
![Page 16: Restful Grails3](https://reader031.vdocuments.mx/reader031/viewer/2022021500/587143671a28ab55588b4eef/html5/thumbnails/16.jpg)
Copyright (c) 2015 Object Computing, Inc. All rights reserved.
Implementing A Custom Renderer
16
![Page 17: Restful Grails3](https://reader031.vdocuments.mx/reader031/viewer/2022021500/587143671a28ab55588b4eef/html5/thumbnails/17.jpg)
Copyright (c) 2015 Object Computing, Inc. All rights reserved.
Registering A Customer Renderer
17
curl -i http://localhost:8080/restconfdemo/people/2.xml
<person yearsOld='16' first='Zack' last='Brown' />
![Page 18: Restful Grails3](https://reader031.vdocuments.mx/reader031/viewer/2022021500/587143671a28ab55588b4eef/html5/thumbnails/18.jpg)
Copyright (c) 2015 Object Computing, Inc. All rights reserved.
Extending RestfulController
18