title: Slim Framework 3 - Create API inside another Slim API or Sharing Routes from different routes?
body: <p>I'm working on an API based system from scratch, and I'm using Slim 3.0.</p>
  
  <p>I want to have different classes that implement \Slim\App as part of it to separate the logic of different API's yet have a unique access point to any of the routes of any of the classes in the API rest.</p>
  
  <p>To accomplish this, I created a base API class that handles the \Slim\App object as part of it.  Also, I created several API classes that inherit from the base class. The next is the base class called "ApiRest".</p>
  
  <pre><code>use Slim\App as ApiSlim;
  class ApiRest
  {
  
      protected $app;
      protected $actualConfiguration;
      protected $middlewares;
  
  
  
      public function __construct($config = [],  $policies=[])
      {
          // ..... previous configuration
          $this-&gt;app = new ApiSlim($this-&gt;actualConfiguration);
  
  
      }//end __construct()
  
  
      public function run($silent = false) {
          $this-&gt;app-&gt;run($silent);
      }
  
      public function getAllRoutes()
      {
          // Slim/Router
          return $this-&gt;app-&gt;getContainer()-&gt;get('router')-&gt;getRoutes();
      }
  
      public function getApp()
      {
          return $this-&gt;app;
      }
  }//end class
  </code></pre>
  
  <p>Then, one of the children class is next:</p>
  
  <pre><code>class ChildApiRest extends ApiRest{
  
      public function __construct() {
  
          parent::__construct([], 'auth');
  
          $this-&gt;app-&gt;get('hello/{name}', function (Request $request, Response $response) {
              $name = $request-&gt;getAttribute('name');
              $response-&gt;getBody()-&gt;write("Hello, $name");
  
              //return $response;
  
          });
  
      }
  }
  </code></pre>
  
  <p>So, the unique access point, just say "api.php" file, is the next one:</p>
  
  <pre><code>$globalRouter = new \Slim\App();
  
  $globalRouter-&gt;group('/services/', function () use($globalRouter){
      $this-&gt;group('oneService/', function () use($globalRouter){
          // At this point I want to "publish" the routes of the specified API
          $apiChild = new ChildApiRest();
          $apiChild-&gt;run();
      });
  
  });
  
  
  $globalRouter-&gt;run();
  </code></pre>
  
  <p>I expect to add as many groups as child API's that I have. With these, I have the routes separated for functionality, but yet remain accessible from one single point (but it's not working).</p>
  
  <p>Finally, when i try to get access to the "hello" api througth this<br>
  "<a href="http://myserver/api.php/services/oneService/hello/world" rel="nofollow">http://myserver/api.php/services/oneService/hello/world</a>", Slim response with 404 error, and the next Fatal error</p>
  
  <p>I get this error:</p>
  
  <pre><code>Fatal error: Uncaught exception 'RuntimeException' with message 
     'Unexpected data in output buffer. 
      Maybe you have characters before an opening &lt;?php tag?' .....
  </code></pre>