-
Notifications
You must be signed in to change notification settings - Fork 2
API access
There is a simple key-based REST'ish API available for use in OT Framework. A few methods are available by default as part of the core of the framework, but you can register more API methods in your module's bootstrap.
In order to consume the API, you need to register a new application for your account with the OT Framework application. This will give you an API key that you will use for all requests to the API. This API key is equivalent to your password, so keep it safe.
As an administrator, you can control access to the API. In Admin -> Users -> User Access Roles. Select the role you'd like to control the access to. In the Remote Access tab, you can change what users who have that role can do with the API.
The API documentation is generated automatically from the docblock comments in the API endpoint's implementation. You can view the documentation in an app by clicking on your account, selecting the API Access tab, and then clicking View API Documentation (https://path-to-otf-app.com/apiapp/api-docs).
OTF adds a resource type so that you can store your API endpoints in the modules folder where they belong. Just like DbTable, Controller, etc., Apiendpoint is stored in /application/modules/yourmodule/apiendpoints
and will be prefixed like other attributes, such as Yourmodule_Apiendpoint_Myendpoint.
Your API endpoint should extend Ot_Api_EndpointTemplate
.
You can add new API endpoints in your custom modules by registering them with the application in your modules' bootstrap file. Here is an excerpt from the application/modules/ot/Bootstrap.php
. You will setup your bootstrap like this.
public function _initApiMethods()
{
$register = new Ot_Api_Register();
$endpoints = array();
$endpoints[] = new Ot_Api_Endpoint('ot-account', 'Deals with the accounts in the system', 'Ot_Apiendpoint_Account');
$register->registerApiEndpoints($endpoints);
}
The arguments are the "name" of the endpoint (basically how you will access it in the URL), a short description, and then the name of the class to be instantiated when the endpoint is called.
The endpoint class is in the application/modules/ot/apiendpoints
folder.
An endpoint can provide methods for get
, put
, post
, and delete
that will be called according to the HTTP method that the requestor uses when making the API call. What happens in these methods is up to you as the developer, but it's best to follow pretty standard REST practices.