我正在尝试从 zend expressive (PSR-7) 应用程序的另一个方法中调用 REST api 端点(内部)。目前我正在做的是,我发送另一个这样的http请求(文档):
$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);
但我想知道,由于我正在尝试调用内部端点,我能否以某种方式转发请求?我听说过控制器插件转发,但我不确定它是如何工作的。
从数据库中检索端点 url 和请求类型。我可以直接调用该方法,但转发端点会减少有条件地检查每个模块所需的工作。
感谢您能指出我正确的方向。
更新:
让我解释一下用例。我们有一个调度程序数据库,其中包含要发送的端点和参数。每 5 分钟 (CRON) 向调度程序 API 发送一个 cURL 请求。调度程序检查数据库中提供的时间间隔,并在此时间间隔触发相应的端点。