Plugins to be used with com_api component
RESTful api is simple joomla plugin, which is same as any other joomla plugin, the difference is only type of plugin. Type must be 'api'
Following well known HTTP methods are commonly used in REST based architecture.
GET - Provides a read only access to a resource.
PUT - Used to create a new resource.
DELETE - Used to remove a resource.
POST - Used to update a existing resource or create a new resource.
- language/en-GB - Resource folder having resource file, keep name same as plugin name.
- en-GB.plg_api_users.ini - add plugin language constant.
- en-GB.plg_api_users.sys.ini
- users - Resource folder having resource file, keep name same as plugin name.
- login.php - Resource file
- users.php - plugin file
- users.xml - xml file
You can add multiple resource in resource folder and use them for different purpose.
Set api group as 'api', add plagin name and other details.
<?xml version="1.0" encoding="utf-8"?>
<extensionversion="3.0.0"type="plugin"group="api"method="upgrade">
<name>PLG_API_USERS</name>
<version>1.6</version>
<creationDate>10/11/2014</creationDate>
<author></author> <description>PLG_API_USERS_DESCRIPTION</description>
<files>
<filenameplugin="your_plugin_name">your_plugin_name.php</filename>
<folder>your_plugin_name(resource folder)</folder> </files>
<languagesfolder="language">
<languagetag="en-GB">en-GB/en-GB.plg_api_plugin_name.ini</language>
<languagetag="en-GB">en-GB/en-GB.plg_api_plugin_name.sys.ini</language>
</languages>
</extension> This file is entry file for api plugin, Change plugin class name 'plgAPIUsers' as per your plugin name 'plgAPIYour_plugin_name'.
You can make resource method public by using setResourceAccess access as $this->setResourceAccess('users', 'public', 'post') Here first param in your plugin name, second is status and last is method, which is you want to make public. Means, it does not need authentication when called.
jimport('joomla.plugin.plugin');
//class structure example//ex - class plgAPIUsers extends ApiPluginclass plgAPIYour_plugin_name extends ApiPlugin
{
publicfunction__construct(&$subject, $config = array())
{
parent::__construct($subject, $config = array());
ApiResource::addIncludePath(dirname(__FILE__).'/users');
/*load language file for plugin frontend*/$lang = JFactory::getLanguage(); $lang->load('plg_api_your_plugin_name', JPATH_ADMINISTRATOR,'',true);
// Set the login resource to be public$this->setResourceAccess('your_plugin_name', 'public', 'post');
}
}All resource file are placed in plugin resource folder.
<?php//class structure example//ex - class UsersApiResourceLogin extends ApiResourceclass Plugin_nameApiResourceResource_file_name extends ApiResource
{
publicfunctionget()
{
// Add your code here$this->plugin->setResponse( $result );
}
publicfunctionpost()
{
// Add your code here$this->plugin->setResponse( $result );
}
}