/redaxo-core:redaxo-api-functionsfrom redaxo-core
Builds HTTP/AJAX endpoints in REDAXO using rex_api_function with class naming conventions, $published flag, JSON responses, and CORS for cross-domain widgets.
Ships in redaxo-core. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
rex_api_function Endpointsrex_api_function is the built-in REDAXO mechanism for HTTP/AJAX endpoints from your own addon. Each endpoint is a class under lib/ that extends rex_api_function. URL: /index.php?rex-api-call=<class_suffix>.
This is not the same as the FriendsOfRedaxo/api addon (which is a full REST framework with route table, OpenAPI, etc.). rex_api_function is the lower-level core feature — perfect for one-off AJAX endpoints in a single addon.
<?php
// lib/api/save_item.php
class rex_api_my_addon_save_item extends rex_api_function
{
protected $published = true; // true = callable from frontend; false = backend only
public function execute()
{
// For JSON request bodies:
$input = json_decode(file_get_contents('php://input'), true);
if (!is_array($input)) {
rex_response::cleanOutputBuffers();
rex_response::setStatus(400);
rex_response::sendJson(['error' => 'Invalid JSON']);
exit;
}
// ...do work...
$result = ['id' => 42, 'saved' => true];
rex_response::cleanOutputBuffers();
rex_response::setStatus(200);
rex_response::sendJson(['data' => $result]);
exit;
}
}
lib/ directory of your addon (autoloaded by REDAXO)rex_api_ — without this, REDAXO doesn't dispatch to it$published flag:
true – endpoint reachable from frontend (no login required)false (default) – only callable when a backend user is logged inexit after sendJson() – REDAXO appends HTML otherwiseGET/POST /index.php?rex-api-call=my_addon_save_item
The URL suffix matches the part of the class name after rex_api_. So rex_api_my_addon_save_item → ?rex-api-call=my_addon_save_item.
When the endpoint is called from a different origin (e.g. an embedded widget on a third-party site), set CORS headers before any output. Only allowlisted origins get CORS headers:
public function execute()
{
rex_response::cleanOutputBuffers();
// CORS preflight + actual response headers – allowlisted origins only
$allowed = ['https://partner1.example', 'https://partner2.example'];
$origin = rex_request::server('HTTP_ORIGIN', 'string', '');
header('Vary: Origin');
if (in_array($origin, $allowed, true)) {
header('Access-Control-Allow-Origin: ' . $origin);
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
}
if (rex_request::requestMethod() === 'options') {
rex_response::setStatus(204);
exit;
}
// ...handle the actual request...
}
Never echo back HTTP_ORIGIN unchecked together with Access-Control-Allow-Credentials: true – any website could then read the response with the visitor's cookies, including a logged-in session. For public, cookie-free data use Access-Control-Allow-Origin: * without the credentials header.
| Source | Code | Notes |
|---|---|---|
| Query string | rex_request::get('id', 'int', 0) | Type-coerced |
| Form body | rex_request::post('name', 'string', '') | Type-coerced |
| JSON body | json_decode(file_get_contents('php://input'), true) | Validate before use |
| Header | $_SERVER['HTTP_AUTHORIZATION'] ?? '' | Apache may strip — see below |
rex_request::get() / rex_request::post() give you type safety for free — prefer them over reading $_GET/$_POST directly.
AuthorizationIf your endpoint reads a Bearer token from the Authorization header and Apache strips it, add to .htaccess:
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
$published = false (or omitting it) and wondering why frontend AJAX gets 403 – set it to true for frontend endpoints.exit after sendJson() – the response gets the JSON, then a blob of REDAXO's normal HTML appended. Browsers parse this as malformed JSON.sendJson() – headers can't be sent after body. Set them first.rex_response::cleanOutputBuffers() – stray output from boot.php (warnings, debug dump() calls) leaks into the response.rex_config::get('my_addon', 'api_key').rex_api_my_addon_save_item must be called as ?rex-api-call=my_addon_save_item, not save_item or my_addon/save_item.requiresCsrfProtection() returns false by default, so any site can trigger a state-changing endpoint in a logged-in visitor's browser. Override it and send the token with the request:
protected function requiresCsrfProtection() { return true; }
// URL/form: rex_api_my_addon_save_item::getUrlParams() or ::getHiddenFields()
The token (rex_csrf_token::PARAM, _csrf_token) is read via rex_request() from $_REQUEST (query string or form field), not from a JSON body or a header. On a missing or invalid token execute() is skipped silently – no HTTP error status.$_POST – $_POST is only populated for application/x-www-form-urlencoded or multipart/form-data. For application/json, read php://input.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub friendsofredaxo/claude-marketplace --plugin redaxo-core11 skills in this plugin
/redaxo-addon-developmentBuilding and maintaining custom REDAXO addons – package.yml, boot.php, install/update/uninstall, lang files, fragments, backend pages, the assets pipeline (and the reinstall-to-sync rule), cache-busting on asset URLs, vendor dependencies, and the common-pitfalls checklist. Use when the user creates a new addon, edits package.yml, sets up backend pages, ships frontend assets from an addon, integrates Composer dependencies, or asks how to package functionality as a reusable addon./redaxo-architectureREDAXO project structure, request lifecycle, and core classes. Use when the user works on a REDAXO codebase, mentions REDAXO directory layout, asks about rex_addon/rex_config/rex_path/rex_url/rex_clang/rex_request, or when files under redaxo/src/, redaxo/data/, or redaxo/cache/ appear in the conversation./redaxo-console-commandsBuilding CLI / diagnostic / maintenance commands for REDAXO addons using Symfony Console (rex_console_command). Covers the class location, naming convention, package.yml registration, and SymfonyStyle helpers. Use when the user adds a CLI tool to an addon, wants a cronjob entry point, builds a diagnostic command, or asks "how do I run X from the command line in REDAXO". Replaces the anti-pattern of writing standalone bootstrap scripts in bin/./redaxo-extension-pointsREDAXO Extension Points – the hook system for modifying core/addon behavior without patching files. Use when the user mentions rex_extension::register, hooks into events like ART_CONTENT / OUTPUT_FILTER / PACKAGES_INCLUDED, or wants to extend backend pages and content./redaxo-metainfo-fieldsDefining and managing REDAXO metainfo fields (cat_*, art_*, med_*) – the SELECT/RADIO/CHECKBOX `params` separator rules (| between options, : inside an option), the SQL-query escape hatch, the rex_metainfo_add_field idempotency caveat, and filtering categories by metainfo via rex_navigation::addFilter. Use when the user adds a metainfo field, sees broken/extra options in a metainfo dropdown, writes idempotent setup scripts that touch metainfo, or filters navigation by category metainfo./redaxo-modulesAuthoring REDAXO modules (input/output PHP) and using REX_VALUE / REX_MEDIA / REX_LINK / REX_LINKLIST / REX_MEDIALIST placeholders. Use when the user creates or edits a module, mentions "Modul" or "Module", works with REX_VALUE[1..20], or builds backend forms for content blocks.Other plugins' skills for the same job