PHP code example of virge / api

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

    

virge / api example snippets



namespace MyProject;

class MyProjectCapsule extends \Virge\Core\Capsule
{
    public function registerCapsule()
    {
        
    }
}

...
parent::registerCapsules(array(
    new MyProject\MyProjectCapsule(),

    new Virge\Api\Capsule(),
    new Virge\Cli\Capsule(),
    new Virge\Cron\Capsule(),
    new Virge\Database\Capsule(),
    new Virge\ORM\Capsule(),
    new Virge\Router\Capsule(),
));
...

Virge\Api::versions([1]);

/**
 * Add namespaces one by one, this would be the start of your namespace, for
 * example, if I had src/Siosphere, my namespace would be Siosphere
 */
$namespaces = array(
    'MyProject',
);



use Virge\Api;

Api::get('hello')
    ->version('all', function() {
        return 'world';
    })
;

Api::verifier('api_key', function($request) {
    return $request->get('apiKey') === '123';
});

Api::get('hello')
    ->verify('api_key')
    ->version('all', function() {
        return 'world';
    })
;

Api::get('hello/{name}')
    ->version('all', function($request) {
        return sprintf("Hello: %s", $request->getUrlParam('name'));
    })
;