Routes are not working in 4.1?

Hey,
im struggling with a custom route. I have also tried a simple one and im getting “'No route found for path: “get-book-code” and request method: “GET””.

Im using valet with php 8.1 working locally.

any hint? httaccess should be modified?

<?php
return [
    'routes' => [
        [
            'pattern' => 'api/get-book-code',
            'method' => 'GET',
            'action'  => function () {
                $codesPage = page('bookcodes'); 
                $bookCodes = $codesPage->bookCodes()->toStructure();

                foreach ($bookCodes as $index => $code) {
                    if ($code->claimed()->toBool() === false) {

                        $updatedCodes = $bookCodes->toArray();
                        $updatedCodes[$index]['claimed'] = 'true';
                        $codesPage->update([
                            'bookCodes' => yaml::encode($updatedCodes)
                        ]);
                        return [
                            'code' => $code->code(),
                        ];
                    }
                }
                return [
                    'status' => 'error',
                    'message' => 'All codes have been claimed.'
                ];
            }
        ]
    ]
];
<?php

return [
    'debug' => true, 
    'routes' => [
        [
            'pattern' => 'api/test',
            'method' => 'GET',
            'action'  => function () {
                return [
                    'status' => 'success',
                    'message' => 'This is a test endpoint.'
                ];
            }
        ]
    ]
];

Perhaps I posted too early: For reference the pattern works without the /api/ part

You cannot use api in a non-api custom route.

So you either need to make thing something/get-book-code.

Or you have to register the route as api route: API | Kirby CMS, but if you do that, you need authentication.