After clicking the 'Create Book' button, a form for the attributes about the book is displayed. After entering the required values, we can click the 'Create' button.
|Create Book Form|
After clicking the 'Create' button the new book properties will be sent to the server and stored in the database. The following screenshot details the request/response transaction from the browser with the client.
Save Book Transition
The important pieces to note are:
- Request URI is http://localhost:8080/research-grails-rest/book/save.
- Request method is POST.
- Response status code is 302.
- Response location is http://localhost:8080/research-grails-rest/book/show/1.
We have now seen three URIs in the transition between book listing, saving and showing a book. The list operation is done with the GET method and the URI was formed as, http://localhost:8080/research-grails-rest/book/list. The save operation is done using the POST method and the URI was, http://localhost:8080/research-grails/rest/book/save. Lastly, the show operation also used a GET method, however specified an id to identify one of the items in the collection like so, http://localhost:8080/research-grails-rest/show/1.
What we have seen so far is the basic blocks to working with a single resource. Later we'll dig in further to understand the request model for updating, deleting and multiple items in the collection. Next we'll take a closer look at REST and put a little more definition around what it is.