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
Content app that defines the backoffice to manage News.
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'
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
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
Webapp for the bundle of Magnolia. The .war generated by this project must be deployed in Tomcat or other servlet container.
> 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
- Starts tomcat
- Open http://localhost:8080/magnolia-headless-example/ from a browser and login with user superuser/superuser
- Access to the content app "Headless Example". Use the search tool at the top
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'
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 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 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
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
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