Laravel RESTful best practices Laravel RESTful best practices symfony symfony

Laravel RESTful best practices


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();});


Sized image files are subordinate resources to the original image resource. So the size info should come after the id: http://example.com/image/3/1024x768 (or since your resolutions are static, you could do somethiing like http://example.com/image/3/large)

If you want to delete original and all sizes, DELETE http://example.com/image/3

If you want to delete a single size, DELETE http://example.com/image/3/1024x768

If you want to upload a new image size, you could do, POST http://example.com/image/3 (use code to check the image size)