# booktics/1.0.19/base/abstracts/base-rest-controller.php

Booktics – Appointment Booking Calendar for Service Businesses, version 1.0.19. 80 lines.

- Page: https://pluginprobe.com/plugins/booktics/1.0.19/code/base/abstracts/base-rest-controller.php
- Raw: https://pluginprobe.com/plugins/booktics/1.0.19/raw/base/abstracts/base-rest-controller.php
- Modified: 2026-04-28T07:37:48+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/booktics/1.0.19/code/base/abstracts/base-rest-controller.php#L10-L20`.

```php
<?php

namespace Booktics\Abstracts;

if ( ! defined( 'ABSPATH' ) ) exit;

use Booktics\Contracts\Hookable_Service_Contract;
use Exception;
use WP_Error;
use WP_HTTP_Response;
use WP_REST_Controller;

/**
 * BaseRest Controller
 *
 * @package Booktics/Abstracts
 */
abstract class Base_Rest_Controller extends WP_REST_Controller implements Hookable_Service_Contract {
    /**
     * Register routes
     *
     * @return  void
     */
    public function register(): void {
        add_action( 'rest_api_init', array( $this, 'register_routes' ) );
    }

    /**
     * Register all routes
     *
     * @return  void
     */
    public function register_routes(): void {
        throw new Exception( 'Need to override register_routes method from child class' );
    }

    /**
     * Send rest error
     *
     * @param string $message Error message
     * @param integer $status_code Error status code
     *
     * @return  WP_HTTP_Response
     */
    public function error( $message, $status_code = 422, $type = '', $details = '' ) {
        $data = array(
            'success' => 0,
            'message' => $message,
            'error'   => array(
                'code'    => $status_code,
                'type'    => $type,
                'details' => $details,
            ),
        );

        return new WP_HTTP_Response( $data, $status_code );
    }

    /**
     * Send rest response
     *
     * @param array $data Response data
     *
     * @return  WP_HTTP_Response
     */
    public function response( $data, $message = '', $status_code = 200 ) {
        if ( ! $message ) {
            $message = __( 'Request was successful', 'booktics' );
        }

        $data = array(
            'success' => 1,
            'message' => $message,
            'data'    => $data,
        );

        return new WP_HTTP_Response( $data, $status_code );
    }
}

```
