Reputation: 495
I have done the backend part of a project in java (Maven) and use a Restful design.
The structur in java/(Maven) is:
1) domainlayer
2) datalayer
3) webservicelayer(client)
And the frontend part will be done in groovy/grails.
The only parts I'm doing to write in grails are: controllers and views.
The structur is:
1)Controllers
2) views
My question is how we can link them two parts together. Since Restful part is written in Maven and creates a war file.
How can I get frontend connected to the backend?
Upvotes: 0
Views: 923
Reputation: 711
REST is talking HTTP so your Grails application will be the client of that. Although, it is a bit wasteful to have Grails in the middle, you can probably design your front-end in JS and do it all in the browser bypassing Grails all-together.
If you are bent on going the Grails way, you will need an HTTP Client (commons HTTP client is a pretty good one) and then on the receiving end you will be able to parse responses, this is where Grails will actually be useful. grails.converters has a nice method for you
JSON.parse(responseText)
It is entirely possible there is a better way of either parsing or doing client HTTP. For example, grails' functional-test plugin wraps HTTP library so you have a bit of a groovy feel for that communication. You might want to look at how it is done there. Not sure if anything better can be done with regards to JSON parsing.
HTH, Alex.
Upvotes: 0
Reputation: 25269
One of the really great features of grails is the GORM, so I'm not sure why you'd want to skip that part. Typically you'd only use a controller if you needed to get some data from a backend and then forward to a view. In your case you've already written the backend, so you could actually just do ajax pages that call the REST interface, and that might be all you need. If that's the case you hardly need grails; you can just put the static pages under your project's src/main/webapp folder and you're done. On the other hand, if you want to use grails for the GSP pages, you can make the controllers be do-nothing (so it's just specifying routes really) and have the view be GSP pages that make ajax calls. If you're going to do this be sure to check out jquery since it has really nice ajax support.
Upvotes: 2