PHP code example of isize1ce / apiate

1. Go to this page and download the library: Download isize1ce/apiate 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/ */

    

isize1ce / apiate example snippets


new ClosureHandler(function(Request $request) {
    return new Response();
}));

class Controller {
    public function methodName(Request $request) {
        return new Response('Hello World!');
    }
}

new ClosureHandler(Controller::class, 'methodName');

class MyRequestHandler implements RouteRequestHandler {
    public function __construct(Request $request) {
        $this->text = $request->request->get('text', 'empty');
    }
    
    public function handle() {
        return new Response('Hello World!');
    }
}

new ClosureHandler(RouteController::class);

$routeProvider->namespace('/path', function(RequestProvider $pathRoutes) {
    $pathRoutes->get('/', SomeHandler);
    $pathRoutes->post('/', SomeHandler);
    
    $routeProvider->namespace('/anotherPath', function(RequestProvider $pathRoutes) {
        $pathRoutes->put('/', SomeHandler);
        $pathRoutes->delete('/', SomeHandler);
    }
}));

$routeProvider->get('/api/{uriParameterNameWithRegex=\d+}/{randomUriParameterWithoutRegex}', SomeHandler);