This module provides a RESTful API base for Kohana 3.3.6 and Koseven 3.3.10 with broad PHP compatibility (5.6 through 8.3). It supports:
- REST verbs:
GET,POST,PUT,DELETE - Output formats:
json,jsonp,xml,txt - Authorization via Bearer tokens
- IP/Referer-based access control
- CORS support
- HTTPS enforcement
- Input sanitization
- Audit logging
modules/api-core/
├── classes/
│ ├── API/
│ │ ├── Auth.php # Authorization and IP/referer checks
│ │ ├── Response.php # Output formatting
│ │ ├── CORS.php # CORS header management
│ │ ├── Log.php # Audit logging
│ │ ├── Sanitize.php # Input sanitization
│ │ └── Security.php # HTTPS enforcement
│ └── Controller/
│ └── Api/
│ └── V1.php # Central API router
├── config/
│ └── api-core.php # Configuration file
├── init.php # Route definition
- Copy
api-coreto yourmodules/directory. - Enable it in
application/bootstrap.php:
Kohana::modules([
'api-core' => MODPATH.'api-core',
// other modules...
]);- Modify
config/api-core.phpas needed:
return [
'allowed_ips' => ['127.0.0.1', '::1'],
'allowed_referers' => ['example.com', 'localhost'],
'tokens' => ['demo_token'],
'allowed_origins' => [],
'enforce_https' => true,
];GET /api/v1/users.jsonPOST /api/v1/orders.xmlPUT /api/v1/products/12.jsonDELETE /api/v1/items/44.txtGET /api/v1/customers.jsonp?callback=render
Authorization: Bearer demo_token
| Feature | Status |
|---|---|
| REST verb routing | ✅ |
| Output formatting | ✅ |
| Token auth | ✅ |
| IP/Referer whitelist | ✅ |
| CORS support | ✅ |
| HTTPS enforcement | ✅ |
| Input sanitization | ✅ |
| Logging | ✅ |
| PHP 5.6 compatible | ✅ |
- Ensure your
.htaccessor server config supports routing toindex.php. - For PUT/DELETE, clients must send the correct
Content-Typeand raw body. - Customize resource controllers under
modules/your_module/classes/Controller/Api/YourResource.php.
Create custom API modules using:
class Controller_Api_Users extends Controller {
public function get() {
$data = ['users' => [...]];
API_Response::send($data, Request::current()->param('format', 'json'));
}
// post, put, delete ...
}For help, contact the maintainer or open a ticket in your project repo.