-1
我與laravel framowork Azure中的 「Web應用程序」。如果我在PHP中創建使用「API管理服務」的REST API,我該如何找回它們從laravel?這是可能的?我是否可以創建應用程序在Azure上的REST API,並與laravel鏈接呢?
我與laravel framowork Azure中的 「Web應用程序」。如果我在PHP中創建使用「API管理服務」的REST API,我該如何找回它們從laravel?這是可能的?我是否可以創建應用程序在Azure上的REST API,並與laravel鏈接呢?
是的,這是可能的。
由於Laravel沒有任何內置的HTTP請求包,你可以考慮以下選項來檢索REST API數據。
$data = json_decode(file_get_contents('https://url_to_the_api'));
$client = new \GuzzleHttp\Client();
$res = $client->request('GET', 'https://api.github.com/repos/guzzle/guzzle');
echo $res->getStatusCode();
// 200
echo $res->getHeaderLine('content-type');
// 'application/json; charset=utf8'
echo $res->getBody();
// '{"id": 1420053, "name": "guzzle", ...}'
// Send an asynchronous request.
$request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org');
$promise = $client->sendAsync($request)->then(function ($response) {
echo 'I completed! ' . $response->getBody();
});
$promise->wait();
我個人更喜歡使用狂飲它可以很容易地集成Laravel,您可以詳細檢查@Mohammed Safeer's answer。