Skip to content

formentor-studio/magnolia-headless-example

Repository files navigation

magnolia-headless-example

Boilerplate for Magnolia CMS headless project.
The bundle includes:

  • Backoffice to contribute contents.
  • Rest service to expose contents.
  • Rest client to get contents from external source (include cache of requests).

The project consists of a News web that provides an API

Modules

Modules

news-module-app

Content app that defines the backoffice to manage News.

news-module-ws

Service that exposes a REST Api to consume News.
Endpoints:

GET news-portal/v1/news
Lists the News in Magnolia. Receives the param dateFrom and the header param accept-languages

$ curl -X GET \
  http://localhost:8080/magnolia-headless-example/.rest/news-portal/v1/news \
  -H 'Authorization: Basic c3VwZXJ1c2VyOnN1cGVydXNlcg==' \
  -H 'Accept-Language: es'

GET news-portal/v1/news/{id} Returns the New for a given id. It uses the value of the header param accept-languages as translation language

$ curl -X GET \
  http://localhost:8080/magnolia-headless-example/.rest/news-portal/v1/news/fd684d86-46c7-46ed-9d4e-f3f0e71a5c17 \
  -H 'Authorization: Basic c3VwZXJ1c2VyOnN1cGVydXNlcg==' \
  -H 'Accept-Language: es'

Swagger

http://localhost:8080/magnolia-headless-example/.rest/swagger.json

http://localhost:8080/magnolia-headless-example/.magnolia/admincentral#app:restTools

Configure swagger.json location in config:modules/rest-tools/config/apiBasePath. Set this value http://localhost:8080/magnolia-headless-example/.rest

More info here https://documentation.magnolia-cms.com/display/DOCS61/REST+module#RESTmodule-RESTToolsmodule-SettingtheAPIbasepath

jokes-module-cli

Rest Client with http://www.icndb.com/ to get jokes.
The requests made to icndb.com are cached in the cache specified at config:modules/jokes-module-cli/config/cacheName

news-portal-and-rest-bundle-webapp

Webapp for the bundle of Magnolia. The .war generated by this project must be deployed in Tomcat or other servlet container.

Installation

> cd magnolia-headless-example
> mvn clean install
> cp ./magnolia-headless-example-webapp/target/magnolia-headless-example.war [PATH_TO_TOMCAT]/webapps

Open http://localhost:8080/magnolia-headless-example and login with these credentials superuser/superuser

Usage

  1. Starts tomcat
  2. Open http://localhost:8080/magnolia-headless-example/ from a browser and login with user superuser/superuser
  3. Access to the content app "Headless Example". Use the search tool at the top Headless content app

Headless content app

4.Create some News
5.Query the news using the REST service

$ curl -X GET \
  http://localhost:8080/magnolia-headless-example/.rest/news-portal/v1/news \
  -H 'Authorization: Basic c3VwZXJ1c2VyOnN1cGVydXNlcg==' \
  -H 'Accept-Language: es'

Configuration

Langs

Allowed languages are configured in Web dev-site:i18n
Translation of literals

More info here https://documentation.magnolia-cms.com/display/DOCS61/Language+configuration

Cache

Cache for jokes is configured in config:/modules/cache/config/cacheFactory/caches

More info here https://documentation.magnolia-cms.com/display/DOCS61/Caching+arbitrary+objects

Rest endpoint

Rest endpoint is configured in config:/modules/news-module-ws/config/rest-endpoints

More info here https://documentation.magnolia-cms.com/display/DOCS61/How+to+create+a+custom+Java-based+REST+endpoint

Rest cli

The client with api.icndb.com is configured at config:/modules/jokes-module-cli/rest-client

More infor here https://documentation.magnolia-cms.com/display/DOCS61/REST+client+module

How to create a magnolia bundle like this

Create custom bundle using maven archetype

$ mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeCatalog=https://nexus.magnolia-cms.com/content/groups/public/ -DarchetypeGroupId=info.magnolia.maven.archetypes

Create modules using maven archetype

$ mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeCatalog=https://nexus.magnolia-cms.com/content/groups/public/ -DarchetypeGroupId=info.magnolia.maven.archetypes

archetype: 3: info.magnolia.maven.archetypes:magnolia-module-archetype (An archetype to create basic Magnolia modules)
info.magnolia.maven.archetypes:magnolia-module-archetype version: 1.2.5
groupId: news.org
artifactId: news-module-cli
version: 1.0-SNAPSHOT
package: news.org
magnolia-bundle-version: 6.1
module-class-name: NewsCli
module-name: news-module-cli

About

Boilerplate for Magnolia CMS headless project.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published