A lightweight, fast PHP API routing framework. Build clean REST APIs without the bloat.
A minimal and elegant routing system for PHP APIs. Define your routes, handle requests, and respond with JSON—that's it.
// In Routes.php
route("GET", "/hello", function () {
echo "Hello World";
});
route("POST", "/login", function () {
Auth()->Login();
});response()
->json(["message" => "Success"])
->setStatusCode(200)
->Send();Define routes using the route() function with:
- HTTP method (GET, POST, DELETE, PUT, PATCH, etc)
- Path (can include dynamic parameters)
- Callback function (your handler code)
When a request arrives, the framework matches it to a route and executes the callback.
Extract values directly from the URL:
route("GET", "/cuts/:id/teste", function ($id) {
echo "You requested item: " . $id;
});Or use regex patterns:
route("DELETE", "/remove/user/(\d+)", function ($id) {
// $id is guaranteed to be numeric
});Access query parameters through PHP's superglobal:
route("GET", "/cuts", function () {
$page = $_GET['page'] ?? 1;
echo "Page: " . $page;
});The dispatch() function:
- Converts your path patterns into regex
- Matches incoming requests against all routes
- Extracts path parameters automatically
- Executes the matching callback with those parameters
The Response class provides a fluent interface for sending JSON:
response()
->json([
"status" => "error",
"message" => "Not found"
])
->setStatusCode(404)
->Send();Simple endpoint:
route("GET", "/hello", function () {
response()->json(["greeting" => "Hello World"])->setStatusCode(200)->Send();
});With parameters:
route("GET", "/users/:id", function ($id) {
$user = User::find($id);
response()->json($user)->setStatusCode(200)->Send();
});With controller:
route("POST", "/signup", function () {
Auth()->Registrar();
});| File | Purpose |
|---|---|
Routes.php |
Define all your API routes |
route_dispatch.php |
Core engine that matches URLs to routes |
Response.php |
Helper class for JSON responses with status codes |
index.php |
Entry point that starts the dispatcher |
controllers/ |
Your business logic and handlers |
Currently in development. Use at your own risk.