REST endpoints enable other software to get real, raw content directly from Magnolia.
This is how mobile apps, front-end JavaScript apps, or systems, like e-commerce or banking systems, can connect with Magnolia.
With our out-of the-box delivery endpoint, this is easy and fast to set up, more powerful and more performant than ever.
This beginner’s tutorial is intended for developers who want to start using Magnolia REST features.
REST endpoints are a powerful tool but can also make your site very vulnerable.
Make sure you understand how to implement a strong security strategy to safeguard your system.
Before enabling and using the REST endpoints in a production environment, get familiar with the REST security topic.
In the context of this tutorial and to get started quickly, we use users with roles provided by the default setup of the Magnolia bundle:
the superuser, the account you log in with to the author instance, has:
Read/Write access for the /* path on every JCR workspace, granted by the superuser role.
Web access for the HTTP GET and POST methods for the /.rest/* path, granted by the rest-admin role, and for the /* path, granted by the superuser role.
Using the delivery endpoint
The delivery endpoint is a REST API provided by Magnolia out-of-the-box.
Use it for obtaining JCR data as JSON.
With version 2 of the Delivery API, you can define multiple endpoint configurations, deliver localized content and resolve references to nodes of other workspaces including assets and asset renditions.
We will create a light module to provide the YAML-based configuration required for the delivery endpoint.
The folder structure and endpoint definition configuration file names you create now may later be used as the value of the endpointPath property.
The endpoint path is used as part of the URL so we recommend you think ahead when naming your files.
In your light-modules folder, which is configured with the magnolia.resources.dir property, create the following structure:
For this particular case, you need to use a URL that contains:
The endpoint path: delivery/demo-content.
The relative path of the node: travel/about.
The URL should then contain /.rest/delivery/demo-content/travel/about.
Next, add the context (the name of the webapp), the domain and the protocol, and you get this URL: http://localhost:8080/magnoliaAuthor/.rest/delivery/demo-content/travel/about.
You are ready to test the endpoint, for example with cURL.
Execute the following curl command:
curl -X GET 'http://localhost:8080/magnoliaAuthor/.rest/delivery/demo-content/travel/about' \
-u superuser:superuserCopy