I have a service running on this url: http://localhost:8888
I get results from this service by invoking it like this:
http://localhost:8888/colors?colorname=red&shade=dark
and I get the results back in JSON like this:
{
"request#": 55,
"colorname": "red",
"shade": "dark",
"available": "No"
}
Question
What are some ways by which I can consume this service in my grails application?
The Grails framework takes advantage of the Model-View-Controller (MVC) design pattern to partition responsibilities within the application and to simplify the application architecture. Model classes should represent the domain objects in your system. Controller classes should control the flow of the application.
Grails is a Java-based web application framework that uses the Apache Groovy programming language.
Assuming all the configuration are there for rest client builder, you would end up with 2 lines of code consuming the service as:
//controller/service/POGO
def resp = rest.get("http://localhost:8888/colors?colorname=red&shade=dark")
resp.json //would give the response JSON
where
//resources.groovy
beans = {
rest(grails.plugins.rest.client.RestBuilder)
}
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