REST запросы
Создаем файл api.php с содержимым
<?php
// Boot up MODX
require_once dirname(dirname(__FILE__)) . '/config.core.php';
require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
$modx = new modX();
$modx->initialize('web');
$modx->getService('error','error.modError', '', '');
// Boot up any service classes or packages (models) you will need
$path = $modx->getOption('mypackage.core_path', null,
$modx->getOption('core_path').'components/mypackage/') . 'model/mypackage/';
$modx->getService('mypackage', 'myPackage', $path);
// Load the modRestService class and pass it some basic configuration
$rest = $modx->getService('rest', 'rest.modRestService', '', array(
'basePath' => dirname(__FILE__) . '/Controllers/',
'controllerClassSeparator' => '',
'controllerClassPrefix' => 'MyController',
'xmlRootNode' => 'response',
));
// Prepare the request
$rest->prepare();
// Make sure the user has the proper permissions, send the user a 401 error if not
if (!$rest->checkPermissions()) {
$rest->sendUnauthorized(true);
}
// Run the request
$rest->process();
в NGINX прописываем настройки
location /rest/ {
try_files $uri @modx_rest;
}
location @modx_rest {
rewrite ^/rest/(.*)$ /rest/index.php?_rest=</head>&$args last;
}
Запросы
- GET /items: вернет список записей
- GET /items/15: вернет запись
- POST /items: создание записи
- PUT /items/15: обновление записи
- DELETE /items/15: удаление
23 февраля 2021, 15:27 2275
Вы должны авторизоваться, чтобы оставлять комментарии.
Комментарии ()