1. Go to this page and download the library: Download incapption/simple-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
incapption / simple-api example snippets
use Incapption\SimpleApi\Models\ApiRequest;
use Incapption\SimpleApi\Models\StringResult;
use Incapption\SimpleApi\Enums\HttpStatusCode;
use Incapption\SimpleApi\Interfaces\iMethodResult;
use Incapption\SimpleApi\Interfaces\iApiController;
class TestController implements iApiController
{
public function get(ApiRequest $request): iMethodResult
{
return new StringResult(HttpStatusCode::SUCCESS(), 'TestController->get()');
}
public function index(ApiRequest $request): iMethodResult
{
return new StringResult(HttpStatusCode::SUCCESS(), 'TestController->index()');
}
public function create(ApiRequest $request): iMethodResult
{
return new StringResult(HttpStatusCode::SUCCESS(), 'TestController->create()');
}
public function update(ApiRequest $request): iMethodResult
{
return new StringResult(HttpStatusCode::SUCCESS(), 'TestController->update()');
}
public function delete(ApiRequest $request): iMethodResult
{
return new StringResult(HttpStatusCode::SUCCESS(), 'TestController->delete()');
}
}
use Incapption\SimpleApi\SimpleApi;
use Incapption\SimpleApi\SimpleApiRoute;
use Incapption\SimpleApi\Tests\Controllers\TestController;
use Incapption\SimpleApi\Tests\Middleware\AuthenticationMiddleware;
class SimpleApiExtension extends SimpleApi
{
public function __construct(string $requestUri, string $requestMethod, array $headers = [], array $input = [])
{
parent::__construct($requestUri, $requestMethod, $headers, $input);
$this->registerRoutes();
}
protected function registerRoutes()
{
// A group which always SimpleApiRoute::registerGet('internal', '/api/schema', TestController::class, 'get', [new AuthenticationMiddleware()]);
}
}
use Incapption\SimpleApi\Helper\HttpHeader;
use Incapption\SimpleApi\Helper\HttpPayload;use Incapption\SimpleApi\Tests\SimpleApiExtension;
$api = new SimpleApiExtension($_SERVER["REQUEST_URI"], $_SERVER["REQUEST_METHOD"], HttpHeader::getAll(), HttpPayload::getInput());
// Check if the actual request is targeted at your API endpoint
if ($api->isApiEndpoint('/api/v1'))
{
$result = $api->getResult();
// Returns the result as JSON and exits the application
$api->sendAndTerminate($result);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.