mahbubhelal/record-api-request 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mahbubhelal/record-api-request

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.

mahbubhelal/record-api-request 适用场景与选型建议

mahbubhelal/record-api-request 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「logging」 「api」 「monitoring」 「middleware」 「request」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mahbubhelal/record-api-request 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mahbubhelal/record-api-request 我们能提供哪些服务?
定制开发 / 二次开发

基于 mahbubhelal/record-api-request 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

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