Simple REST API using Kirby methods

I’ve seen a few threads about REST API for Kirby. It seems like much work.

Would it not be easier to base it on the functions from the cheatsheet?

This code for example:
echo $page->children()->findByURI(‘some-page’)->title();

As url

Some characters are not allowed in an url so it needs to be changed a little bit but something like this:$page-children()-findByURI('some-page')-title()

The advantage would be that it relies more on Kirby and less of own code. To prevent hacking the API could contain a list of allowed function calls, as well as a token.

I don’t think that’s a good solution to be honest. You would need to whitelist every single method of Kirby to make it consistent and even then there’s probably at least one bug in there that makes it possible to execute arbitrary code.

A good REST API starts with a robust URI structure and that would be to only add /api in front of the page URI to make it work like people are used to with HTTP.