I've created API REST collections on my project that will be called both internally (in the same PHP project) and externally (from other projects)
My question is : What is the best way to consume internal API REST ?
I've created a function to mock the call this way :
// init mock
$env = Environment::mock([
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => $path,
'QUERY_STRING' => $urlParams,
'HTTP_AUTHORIZATION' => 'Bearer '.$token
]);
$req = Request::createFromEnvironment($env);
// Instantiate CandidateRoute
$app = (new $class)->get();
$app->getContainer()['request'] = $req;
// Run slim inst
ob_flush();
// Run Slim
$response = $app->run(true);
This is working, but it's still an HTTP call in the end...
Any other way to consume internally API REST ?
Is better to call through CURL instead of mocking ?
Is it OK to make many HTTP calls for API REST that are in the same project ? (I guess no)
Thanks in advance!