1. Go to this page and download the library: Download cdgco/php-rest-service 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/ */
cdgco / php-rest-service example snippets
use RestService\Server;
Server::create('/')
->addGetRoute('test/(\D+)', function($param){
return 'Yay!' . $param; // $param pulled from URL capture group
})
->addPostRoute('foo', function($field1) {
return 'Hello ' . $field1; // same as "return 'Hello ' . $_POST('field1');"
})
->addGetRoute('use/this/name', function(){
return 'Hi there';
})
->run();
namespace MyRestApi;
use RestService\Server;
class Admin {
/*
* @url /test/(\d+)
*/
public function getTest($param) {
return 'Yay!' . $param; // $param pulled from URL capture group
}
public function postFoo($field1){
return 'Hello ' . $field1; // same as "return 'Hello ' . $_POST('field1');"
}
/*
* @url /use/this/name
*/
public function getNotThisName($field1){
return 'Hi there';
}
}
Server::create('/', 'myRestApi\Admin')
->collectRoutes()
->run();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.