jissanto/rapidrest
Composer 安装命令:
composer require jissanto/rapidrest
包简介
High-performance PHP library for building RESTful APIs with modern features like migrations, CLI tools, and more
README 文档
README
A high-performance, developer-friendly PHP library for building RESTful APIs, inspired by modern frameworks like FastAPI and Next.js.
Features
- Modern PHP 8.1+ with strict typing
- Intuitive routing system with support for path parameters
- Middleware support for request/response processing
- Built-in request validation and parsing
- Database migrations with CLI support
- JSON response handling
- PSR-7 compliant HTTP message interfaces
- Clean and maintainable codebase
- CLI tools for common tasks
- Database query builder
- Model relationships
- JWT authentication support
Installation
# Create a new project composer create-project jissanto/rapidrest my-api # Or add to existing project composer require jissanto/rapidrest
Quick Start
<?php require_once __DIR__ . '/vendor/autoload.php'; use RapidRest\Application; use RapidRest\Http\Request; use RapidRest\Http\Response; $app = new Application(); // Add a route with a path parameter $app->get('/hello/{name}', function (Request $request, string $name) { return (new Response()) ->withJson([ 'message' => "Hello, $name!" ]); }); // Run the application $app->run();
Documentation
CLI Commands
RapidRest comes with a powerful CLI tool for managing your application:
# Create a new migration ./rapid make:migration create_users_table # Run migrations ./rapid migrate # Rollback migrations ./rapid migrate:rollback # Refresh database (rollback all and migrate) ./rapid migrate:refresh # Show migration status ./rapid migrate:status
Database Migrations
Create and manage your database schema using migrations:
class CreateUsersTable extends Migration { public function up(): void { Schema::create('users', function (Blueprint $table) { $table->id(); $table->string('name'); $table->string('email')->unique(); $table->string('password'); $table->boolean('is_active')->default(true); $table->timestamps(); }); } public function down(): void { Schema::dropIfExists('users'); } }
Models
Define models with relationships:
class User extends Model { protected static string $table = 'users'; protected array $fillable = [ 'name', 'email', 'password', ]; protected array $hidden = [ 'password', ]; public function posts(): array { return $this->hasMany(Post::class); } public function profile(): Profile { return $this->hasOne(Profile::class); } }
Query Builder
Fluent query building:
// Basic queries $users = User::query() ->where('status', '=', 'active') ->orderBy('created_at', 'DESC') ->get(); // Complex queries $users = User::query() ->select(['users.*', 'profiles.bio']) ->join('profiles', 'users.id', '=', 'profiles.user_id') ->where('users.is_active', '=', true) ->whereIn('users.role', ['admin', 'moderator']) ->limit(10) ->get();
Routing
The routing system supports common HTTP methods and path parameters:
// GET request $app->get('/users', function (Request $request) { return (new Response())->withJson(['users' => []]); }); // POST request with JSON body $app->post('/users', function (Request $request) { $data = $request->getParsedBody(); return (new Response()) ->withJson(['message' => 'User created'], 201); }); // Path parameters $app->get('/users/{id}', function (Request $request, string $id) { return (new Response())->withJson(['id' => $id]); });
Middleware
Add middleware to process requests/responses:
class AuthMiddleware implements MiddlewareInterface { public function process(Request $request, callable $handler): Response { $token = $request->getHeader('Authorization'); if (!$token) { return new Response(401, [], ['error' => 'Unauthorized']); } // Verify JWT token try { $user = $this->jwt->verify($token); $request = $request->withAttribute('user', $user); return $handler($request); } catch (Exception $e) { return new Response(401, [], ['error' => 'Invalid token']); } } } $app->use(new AuthMiddleware());
Validation
Validate incoming requests:
$rules = [ 'name' => 'required|min:2|max:255', 'email' => 'required|email|unique:users', 'password' => 'required|min:8', 'role' => 'in:admin,user,editor', ]; $errors = $this->validate($data, $rules); if (!empty($errors)) { return $this->error($errors, 422); }
Configuration
Copy the .env.example file to .env and update the settings:
DB_HOST=localhost DB_DATABASE=rapidrest DB_USERNAME=root DB_PASSWORD= APP_ENV=development APP_DEBUG=true APP_KEY=your-secret-key JWT_SECRET=your-jwt-secret JWT_TTL=3600
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
jissanto/rapidrest 适用场景与选型建议
jissanto/rapidrest 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「database」 「migrations」 「routing」 「php」 「rest」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jissanto/rapidrest 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jissanto/rapidrest 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jissanto/rapidrest 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
Symfony ClickhouseMigrationsBundle
Very simple SQL-based database migrations tool - a heavily stripped down fork of robmorgan/phinx
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-27