Skip to content

CFM-321_Move_AJAX_API_to_/api/ajax/v2 #123

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion app/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,50 @@

//// API routes
$routes->scope('/api/v2', function (RouteBuilder $builder) {
// BodyParserMiddleware will automatically parse JSON bodies, but we only
// want that for API transactions, so we only apply it to the /api scope.
$builder->registerMiddleware('bodyparser', new BodyParserMiddleware());
/*
* Apply a middleware to the current route scope.
* Requires middleware to be registered through `Application::routes()` with `registerMiddleware()`
*/
$builder->setExtensions(['json']);
$builder->applyMiddleware('bodyparser');
// Use setPass to make parameter show up as function parameter
// Model specific actions, which will usually have more specific URLs:
$builder->post(
'/api_users/generate/{id}',
['controller' => 'ApiV2', 'action' => 'generateApiKey', 'model' => 'api_users'])
->setPass(['id'])
->setPatterns(['id' => '[0-9]+']);
// These establish the usual CRUD options on all models:
$builder->delete(
'/{model}/{id}', ['controller' => 'ApiV2', 'action' => 'delete'])
->setPass(['id'])
->setPatterns(['id' => '[0-9]+']);
$builder->get(
'/{model}',
['controller' => 'ApiV2', 'action' => 'index']);
$builder->get(
'/{model}/{id}',
['controller' => 'ApiV2', 'action' => 'view'])
->setPass(['id'])
->setPatterns(['id' => '[0-9]+']);
$builder->post(
'/{model}',
['controller' => 'ApiV2', 'action' => 'add']);
$builder->put(
'/{model}/{id}',
['controller' => 'ApiV2', 'action' => 'edit'])
->setPass(['id'])
->setPatterns(['id' => '[0-9]+']);
});


//// API Ajax routes
$routes->scope('/api/ajax/v2',
['_namePrefix' => 'apiAjaxV2:'],
function (RouteBuilder $builder) {
// Register scoped middleware for in scopes.
$builder->registerMiddleware('csrf', new CsrfProtectionMiddleware(['httponly' => true]));
// BodyParserMiddleware will automatically parse JSON bodies, but we only
Expand Down Expand Up @@ -93,7 +137,6 @@
->setPatterns(['id' => '[0-9]+']);
});


// Main application routes
$routes->scope('/', function (RouteBuilder $builder) {
// Register scoped middleware for in scopes.
Expand Down
2 changes: 1 addition & 1 deletion app/templates/element/mveaJs.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
getMveas(mveaType,entityType) {
var entityTypeIdRef = entityType + '_id';
let url = '<?=
$this->Url->build(['controller' => 'api', 'action' => 'v2'])
$this->Url->build(['controller' => 'api/ajax', 'action' => 'v2'])
?>/' + mveaType + '?' + entityTypeIdRef + '=<?php print $parentId ?>&extended';
let xhr = callRegistryAPI(
url,
Expand Down