Get the Names of Sites Running in Crafter Engine

In this example we create a simple RESTful service that returns the list of sites running in Crafter Engine. You can find the API for the Context Manager HERE

Prerequisites

  • None

Step 1: Create a REST Controller

  • Under Scripts/rest right click and click create controller
    • Enter get-sites.get as the controller name

  • Add the following code to the controller.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
def siteContextManager = applicationContext["crafter.siteContextManager"]
def siteContextList = siteContextManager.listContexts()
def siteNames = []

siteContextList.each { siteContext ->
    def name = siteContext.getSiteName()
    siteNames.add(name)
}

return siteNames

Step 2: Execute the Service