binaryk/laravel-restify
Composer 安装命令:
composer require binaryk/laravel-restify
包简介
Laravel REST API helpers
关键字:
README 文档
README
Unified Laravel API Layer for Humans and AI
One Codebase. REST for Humans, MCP for AI Agents.
Laravel Restify turns your Eloquent models into both JSON:API endpoints and MCP servers -- automatically. Build once, and instantly serve APIs that work seamlessly for developers, apps, and AI agents.
🚀 The Power of One Codebase
Traditional API development requires separate implementations for different consumers. Laravel Restify changes that:
- 👥 Humans get full-featured JSON:API endpoints
- 🤖 AI Agents get structured MCP (Model Context Protocol) servers
- 🔒 Same Rules - All authentication, authorization, and policies apply to both
- 📝 One Definition - Write your repository once, serve everywhere
Key Features
- JSON:API Endpoints - Full JSON:API specification compliance
- MCP Server Generation - Automatic AI agent interfaces with tool definitions
- Unified Authorization - Laravel policies protect both human and AI access
- Search & Filtering - Powerful query capabilities for all consumers
- Authentication - Laravel Sanctum integration for secure access
- GraphQL Support - Auto-generated GraphQL schemas
- Field Validation - Consistent validation rules across all interfaces
Installation
composer require binaryk/laravel-restify
Quick Start
1. Setup the package:
php artisan restify:setup
2. Create your first repository:
php artisan restify:repository PostRepository --all
3. Enable MCP for AI agents (optional):
Add to your config/ai.php:
use Binaryk\LaravelRestify\MCP\RestifyServer; use Laravel\Mcp\Facades\Mcp; Mcp::web('restify', RestifyServer::class) ->middleware(['auth:sanctum']) ->name('mcp.restify');
That's it! Your API now serves both:
For Humans (JSON:API):
GET /api/restify/posts POST /api/restify/posts PUT /api/restify/posts/1 DELETE /api/restify/posts/1
For AI Agents (MCP):
GET /mcp/restify # Tool definitions and capabilities
Example Repository
use Binaryk\LaravelRestify\Http\Requests\RestifyRequest; use Binaryk\LaravelRestify\Repositories\Repository; use Binaryk\LaravelRestify\Attributes\Model; #[Model(Post::class)] class PostRepository extends Repository { public function fields(RestifyRequest $request): array { return [ field('title')->rules('required', 'string', 'max:255'), textarea('content')->rules('required'), field('author')->readonly(), datetime('published_at')->nullable(), ]; } }
This single definition automatically provides:
- ✅ JSON:API CRUD endpoints with validation
- ✅ MCP tools for AI agents with the same validation
- ✅ Authorization policies applied to both interfaces
- ✅ Search and filtering capabilities for all consumers
One Codebase, Two Outputs
Here's what you get from one repository definition:
For Humans (JSON:API Response)
GET /api/restify/posts
{
"data": [
{
"id": "1",
"type": "posts",
"attributes": {
"title": "Laravel Restify Guide",
"content": "Build APIs fast...",
"published_at": "2024-01-15"
}
}
],
"links": {
"self": "/api/restify/posts",
"next": "/api/restify/posts?page=2"
}
}
For AI Agents (MCP Tool Definition)
GET /mcp/restify # Tool definitions for AI agents
{
"tools": [
{
"name": "posts-index-tool",
"description": "Retrieve a paginated list of Post records from the posts repository with filtering, sorting, and search capabilities.",
"inputSchema": {
"type": "object",
"properties": {
"page": {
"type": "number",
"description": "Page number for pagination"
},
"perPage": {
"type": "number",
"description": "Number of posts per page"
},
"search": {
"type": "string",
"description": "Search term to filter posts by title or content"
},
"sort": {
"type": "string",
"description": "Sorting criteria (e.g., sort=title or sort=-published_at for descending)"
},
"title": {
"type": "string",
"description": "Filter by exact match for title (e.g., title=Laravel). Accepts negation with -title=value"
},
"published_at": {
"type": "string",
"description": "Filter by publication date (e.g., published_at=2024-01-15)"
}
}
}
}
]
}
All generated from this simple repository:
#[Model(Post::class)] class PostRepository extends Repository { use HasMcpTools; public function fields(RestifyRequest $request): array { return [ field('title')->required()->matchable(), field('content'), field('published_at')->rules('date')->matchable(), ]; } }
Restify Boost
Laravel Restify Boost is a development companion that provides MCP server capabilities to help you build Restify APIs faster with AI assistance.
Repository: laravel-restify-boost
Features:
- Documentation access for AI agents
- Repository and action generation assistance
- Code examples and best practices
- Integration with Claude Desktop and other AI tools
Installation:
composer require --dev binarcode/laravel-restify-boost
Templates
Need a production-ready starting point? Check out Restify Templates for complete API starter kits with authentication, permissions, and team management.
Resources
- Documentation - Complete guides and API reference
- Demo Repository - Working example
- Video Course - Visual learning resource
Testing
composer test
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email eduard.lupacescu@binarcode.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
binaryk/laravel-restify 适用场景与选型建议
binaryk/laravel-restify 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 417.75k 次下载、GitHub Stars 达 676, 最近一次更新时间为 2019 年 12 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「rest」 「api」 「crud」 「laravel-restify」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 binaryk/laravel-restify 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 binaryk/laravel-restify 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 binaryk/laravel-restify 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Gii Generator for double model generation
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
Admin panel generator for Laravel 8 and based on Vuetify Admin, a separate SPA admin framework running on top of REST APIs.
Collection of tools to use the full power of the Enyalius framework
Laravel Admin CRUD Generator
统计信息
- 总下载量: 417.75k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 677
- 点击次数: 35
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-15
