Setting up Enonic
In this chapter, we will build a custom app based on the HMDB project, and play around with the Headless API
|For an in-depth introduction to Enonic, visit the official Enonic Developer 101 guide.|
Our platform is actually called Enonic XP (XP, or Enonic for short).
Enonic XP allows you to install and run one or more applications in a single instance.
You can discover ready to run applications on Enonic Market, or you may build your own, like we will be doing in this tutorial. Each app may provide specific functionality. It may for instance be everything you need for a large website, or provide only specific services, such as an API. An app is given an app name when it’s built.
Apps may provide a range of different functionality. For this tutorial we will focus on headless CMS capabilities.
|Useful terminology: A sandbox is a local Enonic server running on your laptop. Apps are built from projects which are basically a folder that contains the app’s source code. Once it is built, it can be deployed to the sandbox - where it will be started and made available.|
Apps typically ship with one or more content types. Content types typically define data structures (similar to fields in classes in object-oriented languages). Each content type gets a unique name which is automatically pre-fixed with the app-name. e.g.
Content types are used to create content items. Content is commonly created and handled via Enonic’s Content Studio. Content may be organised in tree structures, which can be useful both for internal purposes, but also externally - as we will see in this tutorial.
All content items get a unique path name when creating it - this is similar to a filename - and a human-friendly displayName.
Content can exist on two different branches: When creating or editing in Content Studio, you’re always working on the
draft branch. When publishing, new items and changes are copied to the
master branch - which is often publicly accessible.
With Enonic, you may obviously create your own content model, but to save time, we’ll be using a demo-app known as the Headless Movie Database (HMDB) as our starting point.
HMDB ships with a pre-defined content-model and some useful sample content. It also exposes the content through a graphQL API. This API gives us access to the content.
Let’s get going!
Install the Enonic CLI (follow link for instructions).
Create a new project using the "Headless movie database" as your template:
Run the following command from your terminal
enonic project create -r app-hmdb
Stick with the standard values and keep the suggested project name
com.example.myprojectfor the examples in the tutorial to work properly. This will be referred to as app name later in this tutorial.
Deploy the application by running this command from your freshly created project folder.
enonic project deploy
The application will now be built. When asked to start a sandbox (a local instance of XP running its own content storage area), hit Yes. Enonic starts, outputs some server logs, and the sample content is imported.
Install and test Content Studio.
Navigate to http://localhost:8080 and log in to the admin console (you don’t have to create a user for this tutorial).
Install Content Studio (it’s an XP app of its own) by completing the XP Tour , or via the Applications admin app.
From the XP menu, open
Content Studio, and choose the
Headless demoproject if needed. You should see something like this:
Some items have a default preview. That’s okay for now - as we will customize this preview later.
Congrats on setting up the Enonic development environment
With the SDK running, lets have a look at the headless API.