Accessing Kirby content from another site

Hi,

I would like to integrate a Kirby site within a larger php application and I want to retrieve some content from the Kirby site from within the larger application, i.e. the last article written in the Kirby site.

How would you go about this ?

I think I could serve the last article as JSON from within Kirby and call the Kirby URL from the larger application as if it was a web service.

Is there an easier or better way to do something like this ?

gunther

Serving JSON definitely works and is the most reliable but maybe not so fast method (it relies on the web server performance and you would have to encode and decode the information).
If your larger application and your Kirby site live on the same server and your other application has read-access to your Kirby content directory, you can include the Kirby core (bootstrap.php), create an instance of the Kirby class, set the root of the content directory like in the customized folder setup docs on the Kirby object and access your pages directly.

thank you for the tip. I will look into this alternative solution.

You are welcome.
Let me know if something does not work, as I wasn’t able to test that API myself yet, so some information might be wrong.

Finally, I went with my first idea :

  • a json endpoint in the kirby site as explained in this article.

  • a simple web service call from the other application :

    $json = json_decode(file_get_contents($json_url));