diff --git a/notice/api/2.2.md b/notice/api/2.2.md index d5ce47b..6012de5 100644 --- a/notice/api/2.2.md +++ b/notice/api/2.2.md @@ -17,19 +17,19 @@ Links - [(1) setup](#1-setup) - [(2) from php internally](#2-from-php-internally) - [(3) from HTTP requests](#3-from-http-requests) -- [3 - Configuration]() - - [(1) Basic usage]() - - [(2) Advanced usage]() -- [4 - Implementation]() - - [(1) Permissions / AuthSystem]() - - [(2) Modules & methods]() - - [(3) Automatic type check]() +- [3 - Configuration](#3---configuration) + - [(1) Basic usage](#1-basic-usage) + - [(2) Advanced usage](#2-advanced-usage) +- [4 - Implementation](#4---implementation) + - [(1) Permissions / AuthSystem](#1-permissions-/-authsystem) + - [(2) Modules & methods](#2-modules-&-methods) + - [(3) Automatic type check](#3-automatic-type-check) - [5 - Class documentation](#5---class-documentation) - - [(1) Request]() - - [(2) Response]() - - [(3) AuthSystem]() + - [(1) Request](#1-request) + - [(2) Response](#2-response) + - [(3) AuthSystem](#4-authsystem) - [(4) Checker](#4-checker) - - [(4) ModuleFactory]() + - [(4) ModuleFactory](#4-modulefactory) [[2]. Advanced guide]() @@ -54,7 +54,7 @@ Things you **don't have** to do : - API multiple permission management - optional or required inputs - before and after scripts - +- catch both in-URL and `multipart/form-data` input #### (2) Basic knowledge @@ -72,15 +72,17 @@ In order to make the API work, you have to : 2. Implement the Authentication System to manage permissions (cf. [AuthSystem](#3-authsystem)) -#### (2) From php internally +#### (2) Php requirements > ##### 1) include the `autoloader` file + ```php ##### 2) load useful classes + ```php ##### 3) create a request + + + +#### (3) From php internally + + +> ##### 1) create a request + ```php ##### 4) catch possible errors (optional) +> ##### 2) catch possible errors (optional) + ```php ##### 5) execute the request and catch response +> ##### 3) execute the request and catch response + ```php dispatch(); ``` -> ##### 6) catch response errors (optional) +> ##### 4) catch response errors (optional) + ```php ##### 7) catch response output +> ##### 5) catch response output + ```php ##### 1) Format url so it must begin with `/{module}/{method}` + +```php + ##### 2) give the url to the HTTP manager + +```php +error->get() !== Err::Success ) + die('request error'); + + // execute request and catch response + $response = $request->dispatch(); + + // return response as HTTP body + die( $response->serialize() ); +``` + + + +Then can handle various kinds of URL : +> 1. `http://www.host.com/{module}/{method}/` +- parameters can be in URL (separated by `/`) +- parameters can be in `multipart/form-data` or `x-www-form-urlencoded` +- parameters of both URL and content are caught + +> 2. `http://www.host.com/api/{module}/{method}/` +- parameters can be in URL (separated by `/`) +- parameters can be in `multipart/form-data` or `x-www-form-urlencoded` +- parameters of both URL and content are caught + +> 3. `http://www.host.com/` + + +> 4. `https://www.host.com/api/` **Case 2**: You want an URL like `http://www.host.com/api/` and pass all data through POST or form-data.