# 2. Write API READABLE  Category Order (có permission\_callback)

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-MOFjRQUEwbRfINmri0F%2F-MOFo4rmEIvn-87ynn5h%2FScreenshot_3.png?alt=media\&token=c536b806-cb64-4bb8-92a7-b98f2d2e1f8b)

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-MOFjRQUEwbRfINmri0F%2F-MOFoAPXkk78CqghoAvW%2FScreenshot_4.png?alt=media\&token=fc7f4d8f-fc33-4907-b056-b63787136621)

```
<?php
class Lionel_Category_List_Rest extends WP_REST_Controller {
  protected $namespace;
  protected $rest_base;
  public function __construct() {
    $this->namespace = 'categorylist/v2';
    $this->rest_base = 'order';
  }
  public function register_routes() {
    register_rest_route($this->namespace, '/' . $this->rest_base, array(
      array(
        'methods'             => WP_REST_Server::READABLE,
        'callback'            => array($this, 'get_items'),
        'permission_callback' => array($this, 'get_items_permissions_check'),
      ),
      'schema' => null,
    ));
  }
  public function get_items($request) {
    $data  = get_categories();
    $res   = [];
    $index = 0;
    foreach ($data as $list) {
      if ('category' === $list->taxonomy) {
        $temp          = [];
        $temp['name']  = $list->name;
        $temp['id']    = $list->term_id;
        $temp['order'] = $index;
        $res[]         = $temp;
        $index++;
      }
    }
    // Return all of our comment response data.
    return rest_ensure_response($res);
  }
  public function get_items_permissions_check($request) {
    if (!current_user_can('read')) {
      return new WP_Error('rest_forbidden', esc_html__('You cannot view the category resource.'), array('status' => $this->authorization_status_code()));
    }
    return true;
  }
  public function authorization_status_code() {
    $status = 401;
    if (is_user_logged_in()) {
      $status = 403;
    }
    return $status;
  }
}
function register_cat_list_controller() {
  $controller = new Lionel_Category_List_Rest();
  $controller->register_routes();
}
add_action('rest_api_init', 'register_cat_list_controller');
?>
```
