如何在laravel中使用MTA API

时间:2017-12-04 05:50:18

标签: laravel api

我想使用MTA API(大都会运输管理局)服务。但是当我发送请求时,它将返回一个文件。如何从MTA API获取数据?

http://datamine.mta.info/mta_esi.php?key=MYAPIKEY&feed_id=26

1 个答案:

答案 0 :(得分:1)

使用laravel

首先为composer安装guzzlehttp个包
composer require guzzlehttp/guzzle

在控制器中使用它的命名空间:

use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;

然后你就可以了,

$client = new Client();
$api_response = $client->get('http://datamine.mta.info/mta_esi.php?key=MYAPIKEY&feed_id=26');
$response = json_decode($api_response);

// do your stuff with the response