I am trying to call an REST api endpoint(internal) from within another method in zend expressive (PSR-7) application. Currently what I'm doing is, I send another http request like this (docs):
$request = (new Zend\Diactoros\Request())
->withUri(new Zend\Diactoros\Uri('http://example.com'))
->withMethod('PATCH')
->withAddedHeader('Authorization', 'Bearer ' . $token)
->withAddedHeader('Content-Type', 'application/json');
$request->getBody()->write(json_encode($data));
$response = $client->send($request);
But I was wondering since I'm trying to call an internal endpoint, would I be able to forward the request somehow? I've heard of controller plugin forwards, but I'm not sure how that works.
Endpoint url and request type is retrieved from a database. I can call the method directly, but forwarding the endpoint would reduce the work that's required to conditionally check for each modules.
Appreciate if you could point me in the right direction.
Update:
Let me explain the use case. We have a scheduler database which contains endpoints and params to send. A cURL request is sent to the scheduler API every 5 minutes (CRON). Scheduler checks for the interval provided in the db and triggers respective endpoints at this interval.