If you need to provide REST API from your application and you do not want to provide that from other application, there is a way how to do it from Grails even if we run there Vaadin applications.
First thing if you want to have REST API, do not map any Vaadin UI on /* (root) url. If you have to use the root, check the next article "Using root URL for Vaadin app".
Then, we can add URL mapping into UrlMappings.groovy.
class UrlMappings {
static mappings = {
group "/rest", {
"/$controller/$action?/$id?"()
}
}
}
Step 3
Create a controller grails create-controller app.ItemController and implement some logic there. For example, fetch some data from database and return it as JSON. In our example, we will just return a map, with dummy data, as JSON.
package app
import grails.converters.JSON
class ItemController {
def index() {
Map data = ['some': 'data']
return data as JSON
}
}
Step 4
Create two sample Vaadin UIs, so we can verify URL mapping.