You can define a service that acts as a controller and use the __invoke() method to handle incoming requests. This approach can simplify your code because you don’t need to explicitly reference a specific method in the routing YAML file. Instead, you can reference the service ID directly, and Drupal will automatically call the __invoke() method.
Here’s how to implement it: