diff --git a/notice/api/3.0.md b/notice/api/3.0.md index 3e85682..62d1ea8 100644 --- a/notice/api/3.0.md +++ b/notice/api/3.0.md @@ -51,6 +51,10 @@ Plan - [**1** Default Types](#1---default-types) - [**2** Complex Types](#2---complex-types) +[**VI.** Documentation](#vi-documentation) + +- [**1** API accessible documentation](#1---api-accessible-documentation) + # **I.** Overview ## **1** Introduction & features @@ -411,4 +415,14 @@ To add a new type, just open the file `/build/api/Checker.php` and add an entry > **Note:** It is possible to chain `array` type as many as needed. -**Ex.:** `array>` - Will only match an array containing arrays that only contains `id` entries. \ No newline at end of file +**Ex.:** `array>` - Will only match an array containing arrays that only contains `id` entries. + + + +# **VI.** Documentation + +With the *all-in-config* method, we can generate a consistent documentation or other documents from the `/config/modules.json` file. + +## **1** - API accessible documentation + +You can request the API for information about the current URI by using the `OPTIONS` HTTP method. \ No newline at end of file diff --git a/src/config/router/2.0/routes.json b/src/config/router/2.0/routes.json index eb9050c..8019426 100644 --- a/src/config/router/2.0/routes.json +++ b/src/config/router/2.0/routes.json @@ -1,6 +1,6 @@ { - "methods": [ "GET", "POST", "PUT", "DELETE" ], + "methods": [ "GET", "POST", "PUT", "DELETE", "OPTIONS" ], "routes": { @@ -13,12 +13,11 @@ } }, - "/api/{module}/{method}{url_arguments}": { + "/api/v/1.0/{uri}": { + "methods": ["GET", "POST", "PUT", "DELETE", "OPTIONS"], "controller": "api:call", "arguments": { - "module": "[a-zA-Z_]+", - "method": "[a-zA-Z_]+", - "url_arguments": "(\\/[\\w:-]+)*\\/?" + "uri": ".*" } }, diff --git a/src/packages/router/2.0/controller/api.php b/src/packages/router/2.0/controller/api.php index 22d7ef1..6778a66 100644 --- a/src/packages/router/2.0/controller/api.php +++ b/src/packages/router/2.0/controller/api.php @@ -4,6 +4,7 @@ use \api\core\Request; use \api\core\Response; + use \api\core\Loader; class api{ @@ -17,11 +18,13 @@ * */ public function __construct($matches){ + /* (1) Rebuild request url */ - $url = $matches['module'].'/'.$matches['method'].$matches['url_arguments']; + $uri = $matches['uri']; /* (2) Creates request */ - $this->request = Request::remote($url, $_POST); + $this->request = Loader::remote($uri); + } @@ -29,6 +32,7 @@ * */ public function call(){ + /* (1) Process response */ $this->response = $this->request->dispatch(); @@ -37,6 +41,7 @@ echo $this->response->serialize(); return true; + } /* POST-CALL