【问题标题】:Can I create the REST API of my application on azure and link them with laravel?我可以在 azure 上创建我的应用程序的 REST API 并将它们与 laravel 链接吗?
【发布时间】:2017-10-31 12:28:59
【问题描述】:

我在 azure 上有一个带有 laravel 框架的“网络应用程序”。如果我使用 php 中的“api 管理服务”创建 REST API,我如何从 laravel 中检索它们?有可能吗?

【问题讨论】:

    标签: php laravel azure sublimetext2


    【解决方案1】:

    是的,这是可能的。

    由于 Laravel 没有任何内置的 HTTP 请求包,您可以考虑使用以下选项从 REST API 检索数据。

    • cURL

    • file_get_contents

      $data = json_decode(file_get_contents('https://url_to_the_api'));
      
    • Guzzle

      $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 集成的 Guzzle,详情可以查看@Mohammed Safeer's answer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-27
      • 2020-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-10
      • 1970-01-01
      • 2019-06-30
      相关资源
      最近更新 更多