Ideally there would be a plugin that automatically exposed the Grails domain model as OData but I can't see one.
There is OData4j which will let you expose POJOs or JPA as OData however it uses JAX-RS and Jersey under the covers and I'm not sure how to use that inside a Grails application.
I would use Apache Olingo. Follow their Java example and modify for Groovy/Grails like such:
class DataController {
def action() {
// create odata handler and configure it with DemoEdmProvider and Processor
def odata = OData.newInstance()
def edm = odata.createServiceMetadata(new DemoEdmProvider(), [])
def handler = odata.createHandler(edm)
handler.register(new DemoEntityCollectionProcessor())
// let the handler do the work
handler.process(request, response)
return false
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With