Quote from: Jako at Oct 09, 2017, 11:38 AMThe modRestService/modRestController things on https://docs.modx.com/revolution/2.x/developing-in-modx/advanced-development/developing-rest-servers are very straightforward.
Just create everything as mentioned there, use 'modResource' as $classKey in your controllers and you could retrieve (better don't open put/post/delete there) your resources with simple /rest/{controllername} and one resource with /rest/{controllername}/{resource_id}.
If you need to retrieve the tags (do you use Tagger for his?) and the TVs of the blogpost, add the information in a custom afterRead method in your controller class.
Yes blogIt Extra use Tagger for Tags and I really new in this controller thing so I cant figure out myself.
Here is the codes -
box.php
<?php
/**
* Found at: Controllers/Box.php
*
* Handle requests to [URL]/Controllers/Box. Automagically handles CRUD (GET/POST/PUT/DELETE) for the xPDOObject class myBox.
*/
class myControllersBox extends modRestController {
public $classKey = 'modResource';
public $defaultSortField = 'id';
public $defaultSortDirection = 'DESC';
}
rest folder's index.php -
<?php
/**
* Place in /rest/ directory of site. Add .htaccess file above. Note that our REST controllers are in /rest/Controllers/; they can be anywhere though - just change the basePath config option.
*/
/* first load MODX externally */
require_once 'my-public_html/mymodx/config.core.php';
require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
$modx = modX::getInstance('rest');
$modx->addPackage('myblog','my-public_html/mymodx/core/model/');
/* now load the REST service */
$rest = $modx->getService('rest','rest.modRestService','',array(
'basePath' => dirname(__FILE__).'/Controllers/',
'controllerClassSeparator' => '',
'controllerClassPrefix' => 'myControllers',
'xmlRootNode' => 'response',
));
$rest->prepare();
if (!$rest->checkPermissions()) {
$rest->sendUnauthorized(true);
}
$rest->process();
Result :
success false
message "Method not allowed"
object []
code 405
I cant even found a single working example which I can check to figure out how these things works.
Please help me. I just want to get data from my BlogIt posts, tags and normal modx resources to make android apps with REST Api.
http://irresistiblemt.in/appwp/wp-json/wp/v2/posts?fields=id,title,content,featured_media
Here we see that we can fetch id, title, content etc fields and or if we call /posts then we can pull everything.
I want like this(Wordpress) in Modx <3