Extension Key: | expose |
---|---|
Language: | en |
Keywords: | webservice, extbase, xml, json |
Author: | Dominique Feyer <[email protected]> for ttree ltd |
Date: | 2012-04-13 |
Version: | 0.1.0 |
Description: | This is the documentation for the TYPO3 extension expose. Expose extension allow easy setup of readonly web services, configured by TypoScript. |
Contents
This extension provide a simple way to configured how you will expose your Extbase domain model as a standard readonly webservice.
Currently only XML is supported but a JSON and YAML view is planned.
You can configure with properties will be exported in TypoScript.
As Github don't support the all the Restructured Text element used by TYPO3 Documentation Team, please check the RAW README.rst to have proper documentation.
You need to extension the controller abstract class Tx_Expose_MVC_Controller_BasicController, like in this example:
class Tx_Extension_Controller_RecordApiController extends Tx_Expose_MVC_Controller_BasicController {
/**
* @var Tx_Extension_Domain_Repository_RecordRepository
*/
protected $recordRepository;
/**
* @param Tx_Extension_Domain_Repository_RecordRepository $recordRepository
* @return void
*/
public function injectFilmRepository(Tx_Extension_Domain_Repository_RecordRepository $recordRepository) {
$this->recordRepository = $recordRepository;
}
/**
* @return void
*/
public function listAction() {
$records = $this->recordRepository->findAll();
$this->view->setRootElementName('records');
$this->view->assign('record', $records);
}
}
By default the XML view is selected. The root element name can be set with $this->view->setRootElementName($name). To respect RESTful philisophy, you can assign only one variable per action. In this case every domain model in the $records variable will be rendered in a node name "record".
You can include your plugin with the TypoScript configuration:
Example:
lib.api.records = USER lib.api.records { userFunc = tx_extbase_core_bootstrap->run extensionName = Extension pluginName = Api switchableControllerActions { RecordApi { 1 = list 2 = show } } } config { absRefPrefix = http://www.domain.com/ debug = 0 # deactivate Standard-Header disableAllHeaderCode = 1 # no xhtml tags xhtml_cleaning = none admPanel = 0 metaCharset = utf-8 # define charset additionalHeaders = Content-Type:text/xml;charset=utf-8 disablePrefixComment = 1 } page = PAGE page.10 < lib.api.records
With this setup you can use the page cache, to cache the content of your webservice, if this is not what you need you can use a USER_INT.
Note
In a future version, we will integrate the Caching Framework to have a more configurable caching solution.
The administration of the webservice content is done entirely in TypoScript, here is an example of configuration:
Example:
plugin.tx_extension { settings { api { conf { # Configuration for rootElement "records" records { path = api.node.record modelComment = Film Model } } node { record { name { path = name element = completion_date } content { path = content element = content userFunc { class = EXT:extension/Classes/Utility/TextUtility.php:&Tx_Extension_Utility_TextUtility method = cleanTextContent } } country { path = country.name element = country_name } } } } } }
You can add stdWrap parsing with the key "stdWrap" in any node.
A node can be a Content Object element, with this kind of configuration:
Example:
plugin.tx_extension { settings { api { conf { # Configuration for rootElement "records" records { path = api.node.record modelComment = Film Model } } node { record { name { path = name element = completion_date } link = TEXT link { typolink { parameter = 1261 additionalParams = &tx_extension_list[controller]=List&tx_extension_list[action]=show&tx_extension_list[film]={field:uid} additionalParams.insertData = 1 returnLast = url typolink.useCacheHash = 1 } } } } } } }
You can use the element type "relations" to include children element. Each relation element can have their proper configuration (see the conf, key). Currently we support only multiple relation, an example XML output can be:
Example:
<records> <record> <name>Name</name> <groups> <group> <name>Group Name #1</name> </group> <group> <name>Group Name #2</name> </group> </groups> </record> <record> ... </record> </records>
To support for 1:1 relation type is planned, to support output like:
Example:
<records> <record> <name>Name</name> <group> <name>Group Name #1</name> </group> </record> <record> ... </record> </records>
Currently you can include property from a 1:1 relation by setting path to "group.name", to have:
Example:
<records> <record> <name>Name</name> <group_name>Group Name #1</group_name> </record> <record> ... </record> </records>
- Add a security layer The first version will only support a sort of access key. The access key must be provided in the URL to access the service. More advanced security layer can be added later
- Support JSON and other format We can abstract the document creation stack to allow easy support of multiple format like JSON and YAML per example. If you need those formats, you can provide a patch or contact us
- Add support for CRUD operation Currently this not the use case of the extension, but maybe later we can allow CRUD operations on domain model.