uncgits/ccps-api-logging-stats
Composer 安装命令:
composer require uncgits/ccps-api-logging-stats
包简介
API call logging and statistics package for CCPS Framework
README 文档
README
This package is an add-on for apps built with CCPS Core that is designed to provide logging and statistics around the number of API calls made by the application.
This package provides:
- a view and controller
- a database migration
- an Event / Listener pair
Who maintains this?
The UNCG CCPS Developers Group maintains this app - ccps-developers-l@uncg.edu
Installation
1. Require the package
composer require uncgits/ccps-api-logging-stats
2. Register the service provider
Since CCPS Core requires a version of Laravel that includes package auto-discovery, registration of the Service Provider is not necessary.
3. Run the migration
php artisan migrate
4. Add route
In your routes/web.php file, add the statistics page route into your app in your own routes file (pointing to Uncgits\CcpsApiLog\Http\Controllers\StatisticsController@index). Something like:
Route::get('apistats', 'Uncgits\CcpsApiLog\Http\Controllers\StatisticsController@index')
Usage
There is no need to register the event+listener combination in your EventServiceProvider.php file - this is handled in this package's ServiceProvider.php file.
Firing an event
All you need to do when using this package is to fire the event after you attempt an API call. The event expects two parameters - the first parameter is the resultset from the call, and the second is the service name.
So you might do something like this:
// make API call however you do in your package.
$resultset = $api->makeCall('param', 'param', 'etc');
event(new ApiCallAttempted($resultset, 'my-service-name'));
The resultset is an array that should contain at least:
- the method (GET, POST, etc.),
- the endpoint (can be whatever you want - full URI, or a custom string that indicates which API method was hit, etc.)
- the result code (HTTP code, like 200, 403, etc.)
- the result reason ("OK", "Forbidden", etc.)
In the Listener, these values are sought out and passed to the ApiCallStatistic model for insertion into the database:
'service' => $event->service,
'method' => $event->result['response']['method'],
'endpoint' => $event->result['response']['endpoint'],
'result_code' => $event->result['response']['httpCode'],
'result_reason' => $event->result['response']['httpReason']
In the future customization of these keys may be possible, but at present they are hard-coded.
统计信息
- 总下载量: 24
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2017-07-07