Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GORM for Rest (Grails)?

I am doing some research on Grails and writing about what the future holds for it..

Something interesting jumped out in the RoadMap (http://grails.org/Roadmap)

GORM for REST

Anyone with more experience with Grails than me know what this would entail?

I am guessing some sort of CRUD operations through Web Services instead of using Hibernate to connect to an SQL database?

like image 884
mainstringargs Avatar asked Oct 13 '11 01:10

mainstringargs


People also ask

What is Grails Gorm?

GORM is the data access toolkit used by Grails and provides a rich set of APIs for accessing relational and non-relational data including implementations for Hibernate (SQL), MongoDB, Neo4j, Cassandra, an in-memory ConcurrentHashMap for testing and an automatic GraphQL schema generator.

What is Grails in Java?

Grails provides a development environment that includes a web server to get developers started right away. All required libraries are part of the Grails distribution, and Grails prepares the Java web environment for deployment automatically.

What does flush true do in Grails?

flush (optional) - When set to true flushes the persistence context, persisting the object immediately and updating the version column for optimistic locking.


2 Answers

there is a JSON RESTful API for GORM which gives some insight on what GORM for REST is like:

  • GET on /context/api/domain-class-name returns a list of domain objects (possible arguments are the same as for the DomainClass.list() method argument map)
  • POST on /context/api/domain-class-name creates a new instance
  • GET on /context/api/domain-class-name/id retrieves the given instance
  • PUT on /context/api/domain-class-name/id updates the given instance by ID
  • DELETE on /context/api/domain-class-name/id deletes the given instance

As far as to RESTy GORM that is scheduled for Grails 2.0, here is the GORM Virtual REST domain objects discussion on Grails mailing list:

I am currently evaluating the use of grails to connect to other backend systems. Would it be possible to let the domain layer talk to CRUD REST services instead of a Database? It would be a bit like a XML backend.... We have got a very big backend where it is difficult to implement business logic, but we can manage to provide restful services. My idea is to have grails as a business / web application layer on top to deploy various systems to cross platform

This feature is scheduled for development for Grails 2.0 
-- Graeme Rocher
like image 153
tolitius Avatar answered Oct 23 '22 10:10

tolitius


I think the intent is to apply the scaffolding pattern to a RESTful API out of the box. There has been a JIRA entry around for several years for this.

Resulting JIRA: http://jira.grails.org/browse/GRAILS-2823

I also wouldn't be surprised if they took the dynamic finder idea and applied it to URL patterns.

GET /book/findByTitle/Dune

or

GET /book/findByTitle?title=Dune&format=json

or something like that.

I don't know exactly what is on the roadmap, but I imagine that the final product will have scaffold functionality (list,view,create,update,delete) through a RESTful interface plus some URL patterns that correspond to what you can currently do with the dynamic finders that GORM provides.

like image 44
proflux Avatar answered Oct 23 '22 10:10

proflux