承接 faresnassar09/api-vault 相关项目开发

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

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

faresnassar09/api-vault

最新稳定版本:v1.0.0

Composer 安装命令:

composer require faresnassar09/api-vault

包简介

A fluent Laravel package for standardized API responses, smart pagination, and page-aware caching.

README 文档

README

Run Tests

🔐 API Vault

API Vault is a lightweight Laravel utility for building clean, consistent, and chainable API responses with optional caching, callbacks, headers, and response customization.

It helps you avoid repetitive response logic and keeps your controllers clean and readable.

✨ Features

  • Fluent method chaining for API responses
  • Optional caching support
  • Lazy data execution using callbacks (with or without caching)
  • Unified response structure
  • Custom headers & JSON options support
  • Clean and expressive syntax

📦 Installation

composer require faresnassar09/api-vault

🚀 Usage Examples

1️⃣ Basic data response

use FaresNassar\ApiVault\Formatter;

$formatter = new Formatter();

return $formatter
    ->success(true)
    ->message('Users Retrieved Successfully')
    ->data(User::all())
    ->code(200)
    ->send();

2️⃣ Using callback() with caching

return $formatter
    ->success(true)
    ->message('Users Retrieved And Cached Successfully')
    ->cache('users_cache_key', 600)
    ->callback(fn () => User::where('id', '<', 10000)->get())
    ->code(200)
    ->send();

3️⃣ Using callback() without caching

return $formatter
    ->success(true)
    ->message('Users Retrieved Successfully')
    ->callback(fn () => User::all()) // lazy evaluation, no caching
    ->code(200)
    ->send();

4️⃣ Sending additional meta data

return $formatter
    ->success(true)
    ->message('Users Retrieved Successfully')
    ->data(User::all())
    ->additional([
        'cached' => false,
        'execution_time' => '12ms',
        'debug' => true
    ])
    ->send();

5️⃣ Custom headers and JSON options

return $formatter
    ->success(true)
    ->message('Custom Response')
    ->data($data)
    ->headers([
        'X-App-Version' => '1.0.0'
    ])
    ->jsonOptions(JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)
    ->send();

🛠️ Available Methods

  • success() → Set response status (true || false)
  • message() → Set response message
  • data() → Set response data directly
  • cache() → Enable caching (key, seconds)
  • callback() → Lazy data execution (can be used with or without caching)
  • code() → HTTP status code (default: 200)
  • additional() → Set extra meta data
  • headers() → Custom response headers
  • jsonOptions() → Set JSON encoding options (int)
  • send() → Return the final response

📄 Example JSON Response

{
  "success": true,
  "message": "Users Retrieved Successfully",
  "data": [
    {"id": 1, "name": "Fares Ahmed"},
    {"id": 2, "name": "Ali Mohamed"}
  ],

  "code": 200,
  "additional": {
    "cached": false,
    "execution_time": "12ms",
    "debug": true
  }
}

📄 License

MIT License

👨‍💻 Author

Fares Nassar
GitHub: https://github.com/faresnassar09
Email: fares.ahmed.nassar0@gmail.com

Built for clean APIs, not messy controllers 🚀

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固