DevShare
Developer Project Platform
🖥️
API & Backend ⭐ Featured PHP

PHP REST API Framework

John Doe
@johndoe
1.2k views 0 downloads 3h ago
About this project
A lightweight, fast REST API framework built in pure PHP 8.1. Supports routing, middleware, JWT auth, and auto-validation.
Code Snippet
PHP
<?php
class Router {
    private array $routes = [];
    
    public function get(string $path, callable $handler): void {
        $this->routes["GET"][$path] = $handler;
    }
    
    public function dispatch(): void {
        $method = $_SERVER["REQUEST_METHOD"];
        $path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
        
        if (isset($this->routes[$method][$path])) {
            call_user_func($this->routes[$method][$path]);
        } else {
            http_response_code(404);
            echo json_encode(["error" => "Not Found"]);
        }
    }
}
💬 2 Comments

Sign in to leave a comment.

Sign In
Jane Smith 3h ago
This is an excellent framework! I used it for my last project and it saved me hours of setup.
Dev Master 3h ago
Great work! Would love to see middleware documentation.