I'm building a RESTful app with Laravel 4.2, using resource controllers, as described here: https://scotch.io/tutorials/simple-laravel-crud-with-resource-controllers
The app is an online publishing platform. One part of the app allows clients to upload images and crop the images for different publications. Each image may be tagged with title, artist, description.
Typically, the RESTful GET-index request URL would look like this. HTTP GET: example.com/image/
Each image would be retrieved with a URL like this. HTTP GET: example.com/image/{id}
Image number 3 would be deleted with HTTP DELETE to a URL like this. HTTP DELETE: example.com/image/3
However my RESTful dilemma arises because each image must be stored in pre-defined crop sizes. Thus an image resource will share title, artist and description, and will have representations that must be retrievable in four different sizes: Original, 1024x768, 640x480, 320x240
The expected demand is about 80,000 images per year, resulting in 320,000 separate image files (Original + 3 crops each).
Here is where I'm looking for "best-practice" advice...
What should my Image Model look like to allow clients to address an end-point for easy retrieval of each cropped image?
What would be a good way of handling the common nature of title, artist and description?
What would the URLs look like if I wanted to retrieve Image #3 in Original and in 1024x768: Original: example.com/image/??? 1024x768: example.com/image/???
What would the URL look like if I wanted to DELETE all cropped versions of Image #3: HTTP DELETE: example.com/image/???
Thanks for any thoughts you can share!
I don't know how Laravel works with Restful APIs, but in general the rules for urls in Restful APIs a little bit different.
Also I found this article very usefull.
I would argue that the thumbnails are sub-resources of the Image
resource; perhaps a Thumbnail
resource? Therefore, you could have a URL structure something like the following:
Nested resource controllers are achievable in Laravel: http://laravel.com/docs/4.2/controllers#restful-resource-controllers (search for the heading “Handling Nested Resource Controllers”).
This way, you could manipulate individual thumbnail resources, but also images (and any thumbnails) by issuing requests the parent Image
resource—just set up an listener on the Image
model to delete child Thumbnail
resources first when deleting an Image
resource. Something like this:
Image::deleting(function($image)
{
Thumbnail::where('image_id', '=', $image->id)->delete();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With