Setup a frontend to consume API

To use REST API in your frontend app you need at least BEdita 3.6.0 version. You can already also test it using 3-corylus branch.


Because of authentication is handled using Json Web Token (IETF) and the JWT is digital signed using 'Security.salt' you should always remember to change it in app/config/core.php file:

Configure::write('Security.salt', 'my-security-random-string');

Enable API on new frontend app

  • from shell

    cd /path/to/bedita
    ./ frontend init
  • in app/config/frontend.ini.php define $config['api']['baseUrl'] with your API base url, for example

    $config['api'] = array('baseUrl' => '/api/v1');

That’s all! You are ready to consume the API!

Point the browser to your API base url and you should see the list of endpoints available, for example

    "auth": "",
    "me": "",
    "objects": "",
    "posters": ""

Enable API on old frontend app

  • create a new ApiController in your frontend

    require(BEDITA_CORE_PATH . DS . 'controllers' . DS . 'api_base_controller.php');
    class ApiController extends ApiBaseController {
  • in app/config/frontend.ini.php define $config['api']['baseUrl'] with your API base url.

  • edit app/config/routes.php putting

    $apiBaseUrl = Configure::read('api.baseUrl');
    if (!empty($apiBaseUrl) && is_string($apiBaseUrl)) {
       Router::connect($apiBaseUrl . '/*', array('controller' => 'api', 'action' => 'route'));


    Router::connect('/*', array('controller' => 'pages', 'action' => 'route'));

That’s all!

After #570 we have implemented a new (and better) way to handle Exceptions. Remember to update your frontend index.php file:

if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') {
} else {
    $Dispatcher = new Dispatcher();

Also make sure you have defined views/errors/error.tpl in your frontend for generic error handling.