MVC in Dart

images/mvc/get_with_fetch.jpg

The foundation of our Hipster MVC library (of course that’s the name) will be collections of objects, not the objects themselves. The collection maps nicely onto REST-like web services, resulting in a clean API for adding, deleting, and updating records.

Hearkening back to the first chapter, our comics collection can be retrieved via an HTTP GET of /comics. In Hipster MVC parlance, we will call that a fetch.

With REST-like resources, we can also refer to /comics as the URL root because it serves as the root for all operations on the collection of individual records. This is shown in the following sketches.

images/mvc/post_with_add.jpg images/mvc/put_with_save.jpg images/mvc/delete_with_destroy.jpg

Adding a new comic to the collection is an HTTP POST operation on /comics. And, in hipster-ese, that is an add.

To update a comic book with new information, we use HTTP’s PUT, supplying the ID in the subpath of the URL: PUT /comics/42. From Hipster MVC’s perspective, we retrieve the record, update it, and save it with save.

Lastly, to remove a record from the collection, we use the destroy method. This will result in an HTTP DELETE. Again we use the collection URL including the ID.

Let’s get started writing that code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.34.226