Installation:
composer require ibexa/rest
Ensure your config/bundles.php includes Ibexa\Rest\Bundle\IbexaRestBundle.
Enable API:
Add the bundle to your config/packages/ibexa_rest.yaml:
ibexa_rest:
enabled: true
api_version: 'v2'
First Use Case: Test the API with a simple content fetch:
curl -X GET "http://your-site.com/api/v2/content/1" -H "Authorization: Bearer YOUR_TOKEN"
/api/v2/content, /api/v2/search, /api/v2/languages/api/v2/session (POST with credentials).Content Management:
$client = new \GuzzleHttp\Client();
$response = $client->get('api/v2/content/1', [
'headers' => ['Authorization' => 'Bearer YOUR_TOKEN']
]);
$response = $client->post('api/v2/content/1/draft', [
'json' => ['fields' => [...]],
'headers' => ['Authorization' => 'Bearer YOUR_TOKEN']
]);
Search Integration:
/api/v2/search with query parameters:
$response = $client->get('api/v2/search', [
'query' => [
'query' => 'title:example',
'criterion' => json_encode(['ContentType' => ['identifier' => 'article']])
]
]);
Authentication:
$response = $client->post('api/v2/session', [
'json' => ['username' => 'admin', 'password' => 'password']
]);
$response = $client->delete('api/v2/session', [
'headers' => ['Authorization' => 'Bearer YOUR_TOKEN']
]);
Service Integration: Use Laravel's HTTP client to wrap API calls:
use Illuminate\Support\Facades\Http;
$content = Http::withHeaders([
'Authorization' => 'Bearer ' . $token
])->get('api/v2/content/1')->json();
Middleware for API Calls: Create middleware to inject tokens:
public function handle($request, Closure $next) {
$request->headers->set('Authorization', 'Bearer ' . auth()->user()->api_token);
return $next($request);
}
Event-Driven Workflows:
Listen to Ibexa events (e.g., ContentPublish) and trigger API calls:
Ibexa\Core\Event\Content\PublishEvent::class => function ($event) {
Http::post('api/v2/content/' . $event->getContent()->id . '/publish');
}
Custom Endpoints: Extend Ibexa's API by creating custom controllers:
namespace App\Http\Controllers;
use Ibexa\Rest\Server\Controller\Content;
use Symfony\Component\HttpFoundation\Request;
class CustomContentController extends Content {
public function customAction(Request $request) {
// Extend logic here
}
}
Authentication Quirks:
$response = Http::post('api/v2/session/refresh', [
'headers' => ['Authorization' => 'Bearer EXPIRED_TOKEN']
]);
X-Expected-User matches the authenticated user.Content-Type Issues:
supported_media_types flag for file uploads:
$response = Http::post('api/v2/content/1/fields/image', [
'headers' => [
'Content-Type' => 'image/jpeg',
'supported_media_types' => 'image/*'
]
]);
Deprecated Routes:
ibexa.rest.refresh_session; use ibexa.rest.check_session instead.Nested Objects:
ENCODER_CONTEXT may appear in responses; filter it out if needed:
$data = array_filter($response->json(), fn($key) => $key !== 'ENCODER_CONTEXT', ARRAY_FILTER_USE_KEY);
Enable API Debugging:
Set IBEXA_REST_DEBUG=1 in your environment to log requests/responses.
Common Errors:
APP_DEBUG=1).Postman Collection: Use the Ibexa REST API Postman Collection for testing.
Custom Input Parsers:
Extend Ibexa\Rest\Input\Parser\CriterionParserInterface for custom criteria:
namespace App\Rest\Input\Parser;
use Ibexa\Rest\Input\Parser\CriterionParserInterface;
use Ibexa\Rest\Input\Parser\CriterionParser;
class CustomCriterionParser extends CriterionParser implements CriterionParserInterface {
public function parse($value) {
// Custom logic
}
}
Override Serialization:
Extend Ibexa\Rest\Output\Visitor\ValueObjectVisitor for custom field serialization.
Firewall Configuration:
Customize security in config/packages/security.yaml:
firewalls:
api:
pattern: ^/api/v2
stateless: true
provider: ibexa_rest.token_provider
entry_point: ibexa_rest.token_authenticator
Event Listeners:
Subscribe to Ibexa events (e.g., ContentCreateEvent) to react to API changes:
Ibexa\Core\Event\Content\CreateEvent::class => function ($event) {
// Trigger custom logic
}
Pagination:
Use limit and offset for large datasets:
$response = Http::get('api/v2/search', [
'query' => ['limit' => 10, 'offset' => 20]
]);
Caching: Cache frequent API responses in Laravel:
$content = Cache::remember("content_{$id}", 3600, function () use ($id) {
return Http::get("api/v2/content/{$id}")->json();
});
Batch Operations:
Use /api/v2/content/batch for bulk updates/deletes.
How can I help you explore Laravel packages today?