REST and JSON APIs
This page is for developers who expose JSON from controllers or an API framework. Exponential has three ready API layers and the option of plain JSON from a module view. Pick the layer by who calls it.
Contents
- Which layer
- The REST content API
- Your own REST routes
- ezjscore server functions
- expservices
- Plain JSON from a view
- Compared with API frameworks
Which layer
| Caller | Layer | Authentication |
|---|---|---|
| Other programs reading or writing content: apps, front ends, integrations | REST v1 and v2 (ezprestapi) | personal API keys, OAuth2 |
| Your own pages' JavaScript | ezjscore server functions | the session, form token for writes |
| Scripts and apps driving the administration's functions | expservices | API tokens |
| One small endpoint of your module | JSON from a module view | the session or your own check |
The REST content API
Relative to /api/ezp/<version> (REST API v1 and v2 for applications):
| Method | Path | v1 | v2 |
|---|---|---|---|
GET | /content/node/<id> | yes | yes |
GET | /content/node/<id>/list(/offset/<n>)(/limit/<n>) | yes | yes |
GET | /content/object/<id>, .../fields, .../field/<identifier> | yes | yes |
POST | /content/node/create | no | yes |
DELETE | /content/node/delete/<id> | no | yes |
curl -s -H "Authorization: Bearer $EXP_API_KEY" https://example.com/api/ezp/v1/content/node/2Every call checks the user's policies (content/read, content/create, content/edit, content/remove), whatever
the credential. settings/rest.ini configures the framework; [Authentication] RequireAuthentication=enabled is the
default. Under Apache with FastCGI, make sure the Authorization header reaches PHP
(REST API v1 and v2 guide, OAuth and API keys).
Your own REST routes
An extension adds routes with a REST provider registered for a prefix, with a route table and controllers, the way
ezprestapi registers ezp7xRestApiProvider for ezp and ezpl. Route, request, result and response filters are
further extension points (Extension points: REST provider). The
framework authenticates; your controller must authorize.
ezjscore server functions
# extension/expdemo/settings/ezjscore.ini.append.php
[ezjscServer_expdemo]
Class=expDemoServerFunctions
*/ ?><root>/ezjscore/call/expdemo::count::42?ContentType=json calls expDemoServerFunctions::count( array( '42' ) ) and
wraps the return value as {"error_text": "", "content": ...}. ezjscore/call does not check a policy by itself:
every function checks for itself (JSON endpoints with ezjscore).
expservices
expservices turns the administration's functions into over a thousand named services (content, users, roles,
caches, cronjobs, shop, feeds, media, tags, layouts, the audit and more), called through ezjscore with one answer
envelope, discovery and tokens (Remote services with expservices).
Plain JSON from a view
header( 'Content-Type: application/json; charset=utf-8' );
echo json_encode( array( 'ok' => true, 'data' => $data ) );
eZExecution::cleanExit();Fine for one endpoint; for anything larger use a layer above (Responses).
Compared with API frameworks
| Feature | API Platform, DRF, Laravel API resources | Exponential |
|---|---|---|
| Resources from models | generated | the content API covers content; your own resources are routes of a REST provider |
| Serialization | serializers, resources | your controller builds arrays; REST returns fields, optionally rendered as XHTML |
| OpenAPI documentation | generated | not generated |
| GraphQL | available as packages | not in Exponential 6; the Symfony platform products have it (The platform products) |
| Authentication | tokens, OAuth | API keys, OAuth2, expservices tokens |
Related pages
- Headless and decoupled front ends
- APIs and protocols standard
- Remote services and apps
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.