https://github.com/nabeelalihashmi/apilot-engine
Fast router for PHP
https://github.com/nabeelalihashmi/apilot-engine
php php-library php-router php-router-standalone php-routing
Last synced: 6 months ago
JSON representation
Fast router for PHP
- Host: GitHub
- URL: https://github.com/nabeelalihashmi/apilot-engine
- Owner: nabeelalihashmi
- Created: 2022-01-28T11:22:09.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-28T18:00:20.000Z (over 4 years ago)
- Last Synced: 2024-12-29T20:23:15.846Z (over 1 year ago)
- Topics: php, php-library, php-router, php-router-standalone, php-routing
- Language: PHP
- Homepage:
- Size: 228 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Apilot
Fast automatic files based router with Caching routes

### WARNING
Design api carefully
## Installation
### Using Composer
```
composer require nabeelalihashmi/apilot-engine
```
### Manual
Just download the `Apilot.php` file, include in your project. Configure `.htaccess`.
```
on404(function() {
...
});
$apilot->takeoff();
?>
```
### .htaccess files
- Copy extras/root.htaccess in root folder and rename it to .htaccess.
- Copy extras/public.htaccess in public folder and rename it to .htaccess.
## Routes
Make a folder for handlers. Each file in that cockpit folder corresponds to a route.
e.g.
```
cockpit/
index.php -> /
about.php -> /about
contact.php -> contact
...
```
Each file must have at least one handler method. The name of the method must be `handle`.
e.g.
```
function GET() {
}
function POST() {
}
function PUT() {
}
```
## Dynamic routes
To make a route accept dynamic value, use `:` in the route.
e.g.
```
File: cockpit/users/:id/edit.php
URI: /users/:id/edit
function GET($id) {
...
}
s
File: cockpit/users/:id/:action.php
URI: /users/:id/:action
function GET($id, $action) {
...
}
```
## Optional Parameters
To make a route optional, make the parameter optional with `?`.
```
File: cockpit/list/:page?.php
URI: /list/:page?
function GET($page = 1) {
...
}
```
## Rules
* Optional Routes must place at end
```
hello/:who? Good
hello/:who?/level2 Bad
hello/:who?/level2 Bad
```
## Middleware
You can use middleware to do something before and after the route. You can use `before` and `after` appended to handler method name. before middleware must return true to continue.
```
function GET() {
}
function before_GET() {
return true;
}
function after_GET() {
}
```
## Route Not Found
Apilot will call the `on404` function if the route is not found. You can use this function to redirect to 404 page or do something else.
usage:
```
$apilot->on404(function() {
...
});
```