api:2.2 notice in progress 3

This commit is contained in:
xdrm-brackets 2016-12-11 18:45:11 +01:00
parent 5d75e23091
commit 4bccd21c2e
1 changed files with 64 additions and 64 deletions

View File

@ -75,82 +75,82 @@ In order to make the API work, you have to :
#### (2) From php internally #### (2) From php internally
> ##### 1) include the `autoloader` file > ##### 1) include the `autoloader` file
> ```php ```php
> <?php <?php
> require_once '../autoloader.php'; require_once '../autoloader.php';
> ``` ```
> ##### 2) load useful classes > ##### 2) load useful classes
> ```php ```php
> <?php <?php
>
> ... ...
>
> // for API use // for API use
> use \api\core\Request; use \api\core\Request;
> use \api\core\Response; use \api\core\Response;
>
> // for error handling // for error handling
> use \error\core\Err; use \error\core\Err;
>``` ```
> ##### 3) create a request > ##### 3) create a request
> ```php ```php
> <?php <?php
>
> ... ...
>
> // creates a request for the module {module} and its method {method} with params // creates a request for the module {module} and its method {method} with params
> $request = new Request('{module}/{method}', [ $request = new Request('{module}/{method}', [
> 'param1' => 10, 'param1' => 10,
> 'param2' => 'somevalue' 'param2' => 'somevalue'
> ]); ]);
>
>``` ```
> ##### 4) catch possible errors (optional) > ##### 4) catch possible errors (optional)
> ```php ```php
> <?php <?php
>
> ... ...
>
> // if error is not Err::Success // if error is not Err::Success
> if( $request->error->get() !== Err::Success ) if( $request->error->get() !== Err::Success )
> 'do something'; 'do something';
> ``` ```
> ##### 5) execute the request and catch response > ##### 5) execute the request and catch response
> ```php ```php
> <?php <?php
>
> ... ...
>
> $response = $request->dispatch(); $response = $request->dispatch();
> ``` ```
> ##### 6) catch response errors (optional) > ##### 6) catch response errors (optional)
> ```php ```php
> <?php <?php
>
> ... ...
>
> // if error is not Err::Success // if error is not Err::Success
> if( $response->error->get() !== Err::Success ) if( $response->error->get() !== Err::Success )
> 'do something'; 'do something';
> ``` ```
> ##### 7) catch response output > ##### 7) catch response output
> ```php ```php
> <?php <?php
>
> ... ...
>
> // fetch all outputs // fetch all outputs
> $output = $response->getAll(); $output = $response->getAll();
>
> // fetch specific output // fetch specific output
> $specific = $response->get('someOutputName'); $specific = $response->get('someOutputName');
> ``` ```
#### (3) From HTTP requests #### (3) From HTTP requests