1. Go to this page and download the library: Download briedis/api-builder 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/ */
briedis / api-builder example snippets
use Briedis\ApiBuilder\Method;
use Briedis\ApiBuilder\StructureBuilder;
class ExampleGetUserRequest extends Method{
const URI = 'user/get';
const METHOD = 'GET';
public $title = 'User information';
public $description = 'Get user by given ids. One or multiple users can be fetched at once';
public function getRequest(){
return new GetUsersStructure;
}
public function getResponse(){
return (new StructureBuilder)
->struct('users', new UserStructure, 'Array with user objects')->multiple();
}
}
use Briedis\ApiBuilder\StructureBuilder;
use Briedis\ApiBuilder\StructureInterface;
class GetUsersStructure implements StructureInterface {
/**
* Get the structure object
* @return \Briedis\ApiBuilder\StructureBuilder
*/
public function getStructure(){
return (new StructureBuilder)
->int('userId', 'Array of user ids you want to fetch')->multiple()
->int('offset', 'For paging purposes')->optional()
->int('count', 'Amount of users to fetch. Defaults to 20')->optional();
}
}
class UserStructure implements StructureInterface{
/**
* Get User structure object
* @return StructureBuilder
*/
public function getStructure(){
return (new StructureBuilder('User'))
->int('id', 'Unique identifier')
->str('username', 'Nickname that will be used in the system')
->str('firstName', 'Users first name')
->str('lastName', 'Users last name')
->str('gender', 'M - male, F - female')->values(['M', 'F'])->optional()
->int('signature', 'Provide your favorite quote or something, if you want')->optional()
->struct('location', new LocationStructure, 'Location object for the user')->optional()
->int('createdAt', 'Unix timestamp, when user has registered');
}
}
$presenter = new \Briedis\ApiBuilder\Presenter([
new ExampleGetUserRequest,
// Add request class instances as needed
]);
$presenter->setDomain('http://example/api/v1'));
echo $presenter->render();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.