PHP code example of webpractik / api

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

    

webpractik / api example snippets


class ApiRouterExtended extends \Webpractik\Api\ApiRouter
{
	public $sefVariables   = [];
	public $arUrlTemplates = [
		'\MySite\Lk\Response\Resubmit' => 'application/resubmit/',
	];
	public $arLoadModules  = [
		'webpractik.main'
	];
}

class FormRegister extends \Webpractik\Api\Response
{
	public function handler() {
		if (!$this->register()) {
		    $this->response->sendFail('Ошибка регистрации')
		}
		$this->response
		    ->addParam('password', $this->password)
		    ->setSuccess()
		    ->send();
	}

	public function validate() {
		if (!$this->request->getPost('email')) {
		    $this->response->addError('Не введен email');
		}
		if (!$this->request->getPost('login')) {
		    $this->response->addError('Не введен логин');
		}

		return $this->response->haveErrors();
	}
}