From 4bccd21c2eaf0721fa5d62cb77cbb3874715047a Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 11 Dec 2016 18:45:11 +0100 Subject: [PATCH] api:2.2 notice in progress 3 --- notice/api/2.0.md | 128 +++++++++++++++++++++++----------------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/notice/api/2.0.md b/notice/api/2.0.md index e60d964..e3b4939 100644 --- a/notice/api/2.0.md +++ b/notice/api/2.0.md @@ -75,82 +75,82 @@ In order to make the API work, you have to : #### (2) From php internally > ##### 1) include the `autoloader` file -> ```php -> require_once '../autoloader.php'; -> ``` +```php + ##### 2) load useful classes -> ```php -> -> ... -> -> // for API use -> use \api\core\Request; -> use \api\core\Response; -> -> // for error handling -> use \error\core\Err; ->``` +```php + ##### 3) create a request -> ```php -> -> ... -> -> // creates a request for the module {module} and its method {method} with params -> $request = new Request('{module}/{method}', [ -> 'param1' => 10, -> 'param2' => 'somevalue' -> ]); -> ->``` +```php + 10, + 'param2' => 'somevalue' + ]); + +``` > ##### 4) catch possible errors (optional) -> ```php -> -> ... -> -> // if error is not Err::Success -> if( $request->error->get() !== Err::Success ) -> 'do something'; -> ``` +```php +error->get() !== Err::Success ) + 'do something'; +``` > ##### 5) execute the request and catch response -> ```php -> -> ... -> -> $response = $request->dispatch(); -> ``` +```php +dispatch(); +``` > ##### 6) catch response errors (optional) -> ```php -> -> ... -> -> // if error is not Err::Success -> if( $response->error->get() !== Err::Success ) -> 'do something'; -> ``` +```php +error->get() !== Err::Success ) + 'do something'; +``` > ##### 7) catch response output -> ```php -> -> ... -> -> // fetch all outputs -> $output = $response->getAll(); -> -> // fetch specific output -> $specific = $response->get('someOutputName'); -> ``` +```php +getAll(); + + // fetch specific output + $specific = $response->get('someOutputName'); + ``` #### (3) From HTTP requests