...
Tip |
---|
|
Short version - tl;drKey pointsThis section is a very brief summary of the most important things from the sections below. Here we will not go into details but mention the most important points. To use Magnolia REST features: |
Setup
We In this section, we assume you are using a Magnolia bundle with version 5.6 or higher and you know how you canto:
- Install Magnolia.
- Set the
magnolia.resources.dir
property in the magnolia.properties
file. - Start and stop Magnolia.
Bestpractice |
---|
We recommend to you have one common directory for the magnolia.resources.dir on both webapps both magnoliaAuthor and magnoliaPublic webapps. We will use that it later on for a shared configuration. |
...
Required modules
These three The modules listed below are required to use all Magnolia REST features within in a productive context. :
magnolia-rest-integration
magnolia-rest-services
magnolia-rest-content-delivery
When using a preconfigured a preconfigured Magnolia bundle - your webapp(s) , your webapps already contain (s) these three modules. When If you are using a custom webapp or bundle, make sure your custom setup contains the module the modules listed above. See REST module - Installing if you need helpneeded.
While When developing new features, it can be helpful to use the magnolia-rest-tools
module which enable the swagger enables Swagger UI tools. Have a look at enabling swagger UI tools.
Anchor |
---|
| enabling-swagger-tools |
---|
| enabling-swagger-tools |
---|
|
Enabling ...
Swagger UI tools - magnolia-rest-tools
Multiexcerpt include |
---|
MultiExcerptName | general_info |
---|
PageWithExcerpt | _enabling and using swagger |
---|
|
If you do not want to usw use the swagger Swagger UI tools- skip the next sections and proceed with reading about security, skip ahead to security settings.
Installing the magnolia-rest-tools module
To enable swagger you must add magnolia-rest-tools
to your webapp(s).
With Maven
add Add the folowwing following snippet to the pom file of your webapp:
Artifact maven dependencies snippet |
---|
groupId | info.magnolia.rest |
---|
artifactId | magnolia-rest-tools |
---|
|
With a downloaded bundle
If you are running a preconfigured Magnolia Tomcat bundle:
- Stop the Tomcat server (if it was alrewady started).
- Download the Rest the REST tools bundle
Artifact resource link |
---|
groupId | info.magnolia.rest |
---|
artifactId | magnolia-rest-tools |
---|
label | $artifactId.zip |
---|
renderType | download_link |
---|
version | SNAPSHOT |
---|
resourceType | ZIP |
---|
|
. - Unzip the download and copy* all the files to to:
$tomcat/webapps/magnoliaAuthor/WEB-INF/lib
$tomcat/webapps/magnoliaPublic/WEB-INF/lib
(if the direcory directory already exists).
* ) The zip file may contain .jar files which are already present in the WEB-INF/lib
folder of your webapps.
...
Multiexcerpt |
---|
MultiExcerptName | setting-swagger-base-path |
---|
|
The Swagger API explorer tool searches for the API at a path set in /modules/rest-tools/config/apiBasepath . The default value is http://localhost:8080/.rest . The value for this property must match the following pattern: Code Block |
---|
| <protocol>://<hostname>:<port>/<context>/.rest |
When using one of Magnolia's preconfigured bundles running on localhost, set the property to to http://localhost:8080/magnoliaAuthor/.rest . Set the path to where REST services reside on your system. If you run the standard Magnolia bundle and work on the author instance, set the path to http://localhost:8080/magnoliaAuthor/.rest . Advanced Tables - Table Plus |
---|
enableHeadingAttributes | false |
---|
enableSorting | false |
---|
class | m5-configuration-tree |
---|
enableHighlighting | false |
---|
|
Node name | Value |
---|
|
| |
| |
| | http://localhost:8080/magnoliaAuthor/.rest |
|
After setting the base path, restart Magnolia. Swagger UI tools is in Dev > REST Tools. |
Anchor |
---|
| setup-step-by-step |
---|
| setup-step-by-step |
---|
|
Setup Set up a Magnolia bundle with all REST modules - step by step
This section provides a step by step series of instructions to setup set up a Magnolia bundle which that contains all REST modules inclusing including the magnolia-rest-tools
module to use the swagger Swagger UI tools. The procedure is using the uses Magnolia CLI. If you are an experienced Magnolia user, you can skipt skip this and setup set up Magnolia by in your prefered preferred style.
Expand |
---|
title | Click here to expand Expand to see the step by step procedure |
---|
|
#1 Get the shell and choose within. Open a shell and change to the directory of your choice. In our example, we use the directory ~/dev/mgnl-rest-test-base . Code Block |
---|
| cd ~/dev/mgnl-rest-test-base |
|
#2 Downloading | 2 | Download a bundle with Magnolia CLI |
jumpstart. Jumpstart downloads and extracts the latest version of magnolia-community-demo-bundle which comes with Tomcat server. Use the -e option to get the magnolia-enterprise-pro-demo-bundle - which will prompt for enterprise credentials. See jumpstart for further options. Jumpstart also sets the property magnolia.resources.dir in the file magnolia.properties |
- which is fineWhen the execution of doneexecuted, your directory looks like this: Code Block |
---|
mgnl-rest-test-base/
├── apache-tomcat
├── light-modules
└── magnolia.zip |
We will need the light-modules |
folder Please do Do not start the |
tomcat so far#3 Adding the 3 | Add magnolia-rest tools to |
the Download the Rest Download the REST tools bundle Artifact resource link |
---|
groupId | info.magnolia.rest |
---|
artifactId | magnolia-rest-tools |
---|
label | $artifactId.zip |
---|
renderType | download_link |
---|
version | SNAPSHOT |
---|
resourceType | ZIP |
---|
| into a temporary folder. Unzip it |
. Copy of from the unzipped folder into ~/dev/mgnl-rest-test-base/apache-tomcat/webapps/magnoliaAuthor/WEB-INF/lib . Some of the files may already be there |
, that's fine#4 Start Magnolia. You are ready to start |
Magnolia - actually - for the first time. Go to |
our the "root" directory (/dev/mgnl-rest-test-base ) and execute the CLI command start : Code Block |
---|
cd ~dev/mgnl-rest-test-base
mgnl start |
|
Give Magnolia some time. On the first During the initial start up, Magnolia installs a lot of configuration data and demo content bootsrapped with its modules - this may take some time. |
#5 Login on contextOpen favorite login log in as user superuser with the password superuser . Now you are nearly done. |
Play around a little bit with Have a look around Magnolia. |
Also go to context #6 swagger api API path. In order to properly use the |
swagger Swagger UI tools - which are used for development only - |
we adapt change one property in the configuration. On the UAdmin |
- open folder config and edit the property apiBasepath . Give it the value . This property is one of the rare one which requires a server restart to make the change effective. #7 Restart Magnolia | 7 | Restart Magnolia. Go to the shell where you |
have started Magnolia. To stop the server |
- a macMac) or ctrl + C (on Windows). Give the server some time to properly |
shutdownNow Then start it again: Code Block |
---|
cd ~dev/mgnl-rest-test-base
mgnl start |
|
|
Security settings
...
Download | https://curl.haxx.se/download.html |
Positive | Very flexible to tailor the request (method, request headers, user credentials, etc.). Response can be further processed. |
Negative | Not everybody likes command line tools. The response is not easy to read without further tooling. No out of the box automatic URL encoding. |
Tips | On the first atempt of a request use the -i option to display all response headers. If the response body is fine and delivers JSON, pretty print and colorize the response body with tools such as jq. |
Image Modified
Swagger UI tools
If you have not installed magnolia-rest-tools
with the swagger UI tools, skip this section, or see above about how to enable the swagger tools.
Positive | Seamless integrated into the Magnolia UAdmin. Comfortable to use form based interface. |
Negative | The endpoints require specific annotations to make them appear on the swagger UI tools. Delivery endpoint is not annotated and will not appear on the swagger tools. REST request is sent by the user which logged into Magnolia; cumbersome to test with different users. |
Go to Dev > REST Tools.
Multiexcerpt |
---|
MultiExcerptName | swagger-start |
---|
|
When you open the the Magnolia REST Tools app, you should see something similar to this screen:
The Swagger UI lists the bundled endpoints which already have Swagger annotations. These are the endpoints from magnolia-rest-services module (propertiesv1, commandsv2, nodesv1) and one from the cache-browser-app (cachev1). |
...