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