承接 mahbubhelal/record-api-request 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mahbubhelal/record-api-request

最新稳定版本:v1.0.0

Composer 安装命令:

composer require mahbubhelal/record-api-request

包简介

A Laravel package for recording API requests via middleware with a built-in dashboard endpoint.

README 文档

README

A Laravel package for recording API requests via middleware, with a built-in dashboard endpoint for browsing them.

Each request that passes through the middleware is persisted with its timestamp (to millisecond precision), path, status, response time, response length, IP, authenticated user, query string, and user agent. A paginated, sortable listing endpoint is registered at GET /api-requests.

Requirements

  • PHP ^8.3
  • Laravel ^11.0 || ^12.0
  • The dashboard endpoint defaults to being protected by Laravel Sanctum with an access-api-requests token ability. The middleware stack is configurable — see Configuring the dashboard endpoint if you use a different auth driver.

Installation

composer require mahbubhelal/record-api-request

Publish and run the migration:

php artisan vendor:publish --tag=record-api-request-migrations
php artisan migrate

Optionally publish the config file if you want to customise the dashboard route path or middleware stack:

php artisan vendor:publish --tag=record-api-request-config

Recording requests

Apply the RecordApiRequest middleware to the routes you want to track. The middleware records the request during Laravel's terminate phase, so it does not add latency to the response.

For example, to track every route in your api group, add it to bootstrap/app.php:

use Mahbub\RecordApiRequest\Http\Middleware\RecordApiRequest;

->withMiddleware(function (Middleware $middleware) {
    $middleware->api(append: [
        RecordApiRequest::class,
    ]);
})

Or attach it to individual routes:

Route::middleware(RecordApiRequest::class)->get('/orders', ...);

Viewing recorded requests

The package registers GET /api-requests behind auth:sanctum and ability:access-api-requests by default. Issue a Sanctum token with that ability to the users who should be allowed to view the dashboard:

$token = $user->createToken('dashboard', ['access-api-requests']);

Configuring the dashboard endpoint

The middleware stack and route path are driven by config/record-api-request.php:

return [
    'route' => [
        'path' => 'api-requests',
        'middleware' => [
            'api',
            'auth:sanctum',
            'ability:access-api-requests',
        ],
    ],
];

Replace middleware with whatever stack fits your app (e.g. ['web', 'auth'] for a session-authenticated dashboard, or a custom gate middleware) and set path if you want to mount the endpoint somewhere other than /api-requests.

Query parameters

Parameter Description
sort Sort field. Prefix with - for descending. Allowed: time, status, responseTime, responseLength. Defaults to -time.
perPage Page size. Defaults to 15.
page Page number. Defaults to 1.

Response shape

{
    "data": {
        "amountPerPage": 15,
        "page": 1,
        "totalAmount": 120,
        "totalPages": 8,
        "requests": [
            {
                "time": "2026-04-09 14:23:11.482",
                "status": 200,
                "responeTime": "42ms",
                "responseLength": "1.2kB",
                "ip": "203.0.113.7",
                "user": "Ada Lovelace (ada@example.com)",
                "url": "https://example.test/api/orders?status=active",
                "userAgent": "Mozilla/5.0 ..."
            }
        ]
    }
}

Development

The package ships with a Docker-based dev environment. Common commands:

./dc buildup          # build and start the containers
./dc pest             # run the test suite
./dc pest --coverage  # run tests with coverage
./dc phpstan          # run static analysis
./dc pint             # run the formatter
./dc rector           # run automated refactors

License

The MIT License (MIT). See LICENSE.

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固