For the past few projects I’ve worked on, I have been doing things like cropping/resizing images via url endpoints (like in the early 2.3 beta) and returning page objects as json. This plugin adds a route to your site that lets you create APIs that do things like this very easily.
Check out the repository for full overview and documentation, but in a gist:
Services
The Sirvy plugin provides 3 simple services (by default):
json
returns page contents as json:
/sirvy/home?service=json
resize
returns a resized thumbnail:
/sirvy/home?service=resize&image=image.jpg&width=400
crop
returns a cropped thumbnail:
/sirvy/home?service=crop&image=image.jpg&width=200&height=300
However, you can easily edit these services or write your own to cover any functionality you need from your API!
Page Method
A Sirvy page method is exposed to make generating endpoint URLs super simple from within your templates:
page('home')->sirvy('json');
// -> http://yourkirby.com/sirvy/home?service=json
This is great for spitting out many thumbnails without blocking initial page render:
foreach ($hundredsOfImages as $i) {
echo '<img src="' . $page->sirvy('resize', [
'image' => $i->filename(),
'width' => 500
]) . '">';
}
Hopefully someone will find this handy!