Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleExpand to see the step by step procedure


StepInstructions
1

Choose a directory to work in.

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
languagebash
cd ~/dev/mgnl-rest-test-base


2

Download a bundle with Magnolia CLI.

Code Block
languagebash
mgnl 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.

Once jumpstart is executed, your directory looks like this:

Code Block
mgnl-rest-test-base/
├── apache-tomcat
├── light-modules
└── magnolia.zip

We will need the light-modules folder later on. (warning) Do not start the Tomcat server yet.

3

Add magnolia-rest tools to your bundle.

Download the REST tools bundle 

Artifact resource link
groupIdinfo.magnolia.rest
artifactIdmagnolia-rest-tools
label$artifactId.zip
renderTypedownload_link
versionSNAPSHOT
resourceTypeZIP
into a temporary folder. Unzip it and copy all the files 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.

4

Start Magnolia.

You are ready to start the Tomcat server for the first time. Go to the "root" directory (/dev/mgnl-rest-test-base) and execute the CLI command start:

Code Block
cd ~dev/mgnl-rest-test-base
mgnl start

(info) 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

Log in to the author instance.

In your preferred browser, open the URL http://localhost:8080/magnoliaAuthor/ and log in as user superuser with the password superuser.

Now you are nearly done. Have a look around Magnolia. Access the public instance with the URL http://localhost:8080/magnoliaPublic/ .

6

Set the Swagger base API path.

In order to properly use the Swagger UI tools - which are used for development only - you must change one property in the configuration.

On the UAdmin, open the Configuration app and find the node /modules/rest-tools/config. (You can use the URL http://localhost:8080/magnoliaAuthor/.magnolia/admincentral#app:configuration:browser;/modules/rest-tools/config:treeview: to go there directly.)

Open the config folder and change the value of the apiBasepath property to: http://localhost:8080/magnoliaAuthor/.rest

7

Restart Magnolia.

Go to the shell where you started Magnolia.

To stop the server, press cmd + C (on Mac) or ctrl + C (on Windows). Give the server some time to properly shut down.

Then start it again:

Code Block
cd ~dev/mgnl-rest-test-base
mgnl start



Anchor
security
security
Security settings

We have warned you


Notewarning

Multiexcerpt include
MultiExcerptNamegeneral-security-advice
PageWithExcerptREST security
.

Please You must read and understand REST security before enabling and using the REST endpoints on in a productive environment.

In the context of this tutorial and to get started quickly, you will we use users with roles provided by the default setup of the the the Magnolia bundle.

Using superuser

...

 in the author

...

instance - for testing

...

purposes only

...

On In the author context the superuser is grantedinstance, superuser has:

  • Read/Write access for the path / on every JCR workspace - workspace, granted by the role   superuser role.
  • Web access for the HTTP methods 
    Mgnl get
    Mgnl put
    Mgnl post
     and 
    Mgnl delete
     for the path /magnoliaAuthor/.rest* - granted by the role rest-admin.

Note that superuser is given a lot of power. Use it carefully in the context of this tutorial.  But never use superuser on a productive environment.

Using anonymous

...

 in the public

...

instance

The public context instance is typically is visited by users which who do not authenticate. Nevertheless, such These visits are done as as the anonymous user - which , who also has some permissions.

On In the public context anonymous user is grantedinstance, anonymous user has:

  • Read access on the path / for the JCR workspaces websitedamgoogleSitemapscategory,  and tours.
  • Web access for the HTTP method 
    Mgnl get
     on the path  path method GET  for the path /magnoliaAuthor/.rest/delivery/*

As you can see, anonymous user only has read access and can only access the Delivery endpoint. That is sufficient for the moment.

On In a productive environment - we highly recommend to recommend you create custom REST roles granting specific access for specific use cases.

...

REST endpoints - an overview

Magnolia provides the following REST endpoints out-of-the-box the following REST endpoints:

Multiexcerpt include
MultiExcerptNameendpoints-overview
PageWithExcerptREST API

If you want to use REST to create, update and delete content - , we recommend using you use the Nodes endpoint which supports all required operations. If you mainly want to read data - , consider using the Delivery endpoint. It provides a very handy convenient, formatted JSON and can be customized and configured with YAML via light module. With the Commands endpoint you can trigger commands . And and Cache endpoint deals with cache. And you always

You can also create your own custom endpoints - for inspiration see How to create a custom Java based REST endpoint

Tools to test REST requests

On In this section, we propose suggest some tools you can use to test the REST API - without the need needing to develop a REST consuming client application. Testing your REST requests is handy useful when you are developing client apps and similar things which will that interact with the REST endpoints.

...

Browsers

PositiveFor instance Firefox displays JSON and XML in a very well readable format. 
Negative

A browser provides only limited control to tailor a request without further add-ons. Requests are sent as 

Mgnl get
GET and you cannot add more request headers out of the box.

Tips

If you want to test on REST resources via 

Mgnl get
GET, which requires authetication (to get assigned roles not provided to anonymous user - login at Magnolia first, open a new tab on the same window (using the same session) and then requesting the REST resource.

Upgrade the browser with add-ons to extend its possibilities to controll the request.

...