从 --->>> 一个非常极简的HTTP--->>> 框架 开始
php 版本放了比较高,8.5。
<?php
declare(strict_types=1);
/** * 安心站长axzz.cn,一个追求技术创造者。让网站、小程序、APP牛起来…… * * cighsen02 365182575 * * Create at: 2026.01.18 */
use Uri\Rfc3986\Uri;
/** * 使用 comopser */ require __DIR__.'/../vendor/autoload.php';
$stringUri = $_SERVER['REQUEST_URI'] ?? '/'; $method = $_SERVER['REQUEST_METHOD'] ?? 'GET'; $path = new Uri($stringUri)->getPath();
/** * json响应 */ header('Content-Type: application/json; charset=utf-8'); if ($method === 'GET' && $path === '/health') { json_response(['ok' => true, 'time' => date(DATE_ATOM)]); } if ($method === 'POST' && $path === '/users') { $body = read_jsonBody(); $email = strtolower(trim((string) ($body['email'] ?? ''))); $name = trim((string) ($body['name'] ?? '')); if (! filter_var($email, FILTER_VALIDATE_EMAIL)) { json_response(['error' => 'Invalid email'], 422); } if ($name === '') { json_response(['error' => 'Name is required'], 422); } $id = random_int(1000, 9999); json_response(['id' => $id, 'email' => $email, 'name' => $name], 201); } json_response(['error' => 'Not found'], 404);
最简单已经实现了
完整代码: https://gitee.com/twoir/ecmsapi/tree/ecmsapi-dev
|