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.
Permalink
Failed to load latest commit information.
directoryutils
LICENSE
README.md
TestClass.groovy
assets.groovy

README.md

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, Random.org and JSONPlaceholder.

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

Usage:

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

// Load SourceGrape artifact from the Maven repo
@Grab('com.sourcegrape:sourcegrape')
import com.sourcegrape.*

// Load the directory
@SourceGrab('https://github.com/andresviedma/groovy-assets-directory-example.git')
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()

rest.marvel.characters
characters = rest.marvel.characters()
pretty characters.data.results.collect { "${it.id}: ${it.name}" }
warlock = characters.data.results.find { it.name == 'Adam Warlock' }
rest.marvel.characters."${warlock.id}".series
series =  rest.marvel.characters."${warlock.id}".series();
pretty series.data.results*.title