No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Groovy Microservices Directory example

Demo repository with an example creating a directory of microservices accesible through the Groovy shell. The directory makes use of Groovy SourceGrape and Groovy DynApiClient.

For this demo we have used public APIs instead of microservices, concretely the Marvel API, and JSONPlaceholder.

The whys and hows of this idea are explained in 'Operating Microservices with Groovy'.


  1. Copy this in your local ~/.groovy/groovysh.profile
println "Loading assets directory"

// Load SourceGrape artifact from the Maven repo
import com.sourcegrape.*

// Load the directory
directoryLoaded = true
bootstrap = new directoryutils.AssetsDirectoryBootstrap()
binding.variables << bootstrap.getAssetsDirectory(this)
  1. Start the groovysh
  2. Call the registered demo services!
  3. If you want to call also the Marvel API, copy this in ~/.groovy/assets_secret.groovy using your API Keys
auth {
    marvel {
        publicKey = '<your-marvel-api-public-key>'
        privateKey = '<your-marvel-api-private-key>'
    random {
        apiKey = '<your-random-org-api-key>'

Examples of demo services calls

pretty jsonrpc.random.generateIntegers(n: 6, min: 1, max: 60)
pretty jsonrpc.random.generateUUIDs(n: 2)

pretty rest.jsonplaceholder.posts."37".comments()
pretty rest.jsonplaceholder.posts."37"()
rest.jsonplaceholder.posts."37" = [title: 'Hi!', id: 37, userId: 4, body: 'Good morning.']
println rest.jsonplaceholder.posts << [title: 'Hi!', id: 3747634, userId: 4, body: 'Good morning.']
println rest.jsonplaceholder.posts.add([title: 'Hi2!', id: 3747635, userId: 4, body: 'Good morning again.'])
println rest.jsonplaceholder.posts."37".delete()

characters = rest.marvel.characters()
pretty { "${}: ${}" }
warlock = { == 'Adam Warlock' }
series =  rest.marvel.characters."${}".series();