Nesting custom API routes

Hi all,

Does Kirby support nested custom API routes like below? I’ve got the following setup in a plugin but getting a 404 when hitting /api/roles/resources. I’m on v4.7.0.

/api/roles
/api/roles/resources

./my-plugin/extensions/api.php

<?php

return [
	'routes' => [
		[
			'pattern' => 'roles',
			'action'  => function () {
				$role = new Role();
				return $role->getAllRoles();
			}
		],
		[
			'pattern' => 'roles/resources',
			'action'  => function () {
				$resource = new Resource();
				return $resource->getAllResources('wunderbaum');
			}
		],
	]
];

The nesting should not be a problem, but rather maybe something going wrong in the action callback?

Hm I don’t think so, cause when I change the pattern to e.g. just resources it works as expected.

My guess is that it might clash with the resources/(:any) route

1 Like

I think you’re right. I didn’t notice that endpoint /roles already exists. I’m going to rename my routes. Thanks both of you!