hiraq / drapi
A framework to create and manage API services
Requires
- php: >=5.3.0
- league/phpunit-coverage-listener: ~1.0
- monolog/monolog: >=1.5.0
- zendframework/zend-http: >=2.2
- zendframework/zend-json: >=2.2
- zendframework/zend-uri: >=2.2
- zendframework/zend-validator: >=2.2
Requires (Dev)
- phpunit/phpunit: >=3.7.0
This package is not auto-updated.
Last update: 2024-12-16 16:38:10 UTC
README
A framework to create and manage API (REST) services
usage
Put this codes in your index.php
file.
<?php
require_once 'vendor/autoload.php';
use Drapi\Router;
use Drapi\Request as DrapiRequest;
use Drapi\Response as DrapiResponse;
use Drapi\Handler;
use Drapi\Compiler;
try {
$router = new Router;
$request = new DrapiRequest;
$response = new DrapiResponse;
$handler = new Handler;
$compiler = new Compiler($router,$request,$response);
$compiler->setHandlerNameSpace('Drapi\\Handler\\');
$compiler->setHandler($handler);
$compiler->compile();
} catch (Exception $e) {
echo $e->getMessage();
}
Then try to open your browser, and go to
http://localhost/myapi/test
orhttp://localhost/myapi/test/get
http://localhost/myapi/testing
for failed data response examplehttp://php.drapi/test/test_param?key1=val1&key2=val2
for GET parameters example
Drapi doesn't need any rewrite rules!
handler
A handler is class to manage and return a data from your datasource (MySQL,Postgre,Mongodb,etc).
Create a handler class inside Drapi/Handler, such as Users.php
. Everytime your server get a
API request based on: '/users/get', then your handler (Users.php) will be loaded and will use method get
inside Users class. See Test.php inside Drapi/Handler for example.
plugin
A plugin is an extension for your handler class, create a class such as Mongo.php in Drapi/Handler/Plugin and load this class inside your handler class (autoload).
response
All Drapi response is a data formatted in json. If any request that fail to call a handler or maybe there are no valid data available, then Drapi will automatically give an error status and message.
license
Drapi is released under the BSD 3-Clause License. See LICENSE.txt file for details.