=========== RESTful API =========== .. sectionauthor:: Bernhard Posselt Offering a RESTful API is not different from creating a :doc:`route ` and :doc:`controllers ` for the web interface. It is recommended though to inherit from ApiController and add **@CORS** annotations to the methods so that `web applications will also be able to access the API `_. .. code-block:: php 'author_api#preflighted_cors', 'url' => '/api/1.0/{path}', 'verb' => 'OPTIONS', 'requirements' => array('path' => '.+') ) Keep in mind that multiple apps will likely depend on the API interface once it is published and they will move at different speeds to react to changes implemented in the API. Therefore it is recommended to version the API in the URL to not break existing apps when backwards incompatible changes are introduced:: /index.php/apps/myapp/api/1.0/resource Modifying the CORS headers ========================== By default the following values will be used for the preflighted OPTIONS request: * **Access-Control-Allow-Methods**: 'PUT, POST, GET, DELETE, PATCH' * **Access-Control-Allow-Headers**: 'Authorization, Content-Type, Accept' * **Access-Control-Max-Age**: 1728000 To add an additional method or header or allow less headers, simply pass additional values to the parent constructor: .. code-block:: php