Can i provide an api via subdomain?

Hi,

i want to build an api that returns a json object of my kirbypages. I want to use this api with a subdomain.
E. g.: api.domain.com?pages=all

Its the same kirby site. My questions:

  1. Do i need another licence for this?
  2. Can i provide such an api with custom routes and subdomains???

Thanks for your answers.

  1. This is no official answer, but I’d say no. It’s the same site and the same content after all.
  2. Yeah, sure. You will have to make sure in your web server config that both domains point to the same directory though. In a Kirby plugin, you can then check for Url::host() to be api.domain.com. If it is, register your API routes and bypass the normal template generation by halting execution from your plugin after you sent a response.
1 Like