Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6074195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:21:18+00:00 2026-05-23T10:21:18+00:00

I am writing a Grails app, and I want the controller to hit some

  • 0

I am writing a Grails app, and I want the controller to hit some other API with a POST and then use the response to generate the page my user sees. I am not able to Google the right terms to find anything about posting to another page and receiving the response with Grails. Links to tutorials or answers like “Thats called…” would me much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:21:18+00:00Added an answer on May 23, 2026 at 10:21 am

    Seems like you are integrating with some sort of RESTful web service. There is REST client plugin, linked here.

    Alternatively, its quite easy to do this without a plugin, linked here.

    I highly recommend letting your controller just be a controller. Abstract your interface with this outside service into some class like OtherApiService or some sort of utility. Keep all the code that communicates with this outside service in one place; that way you can mock your integration component and make testing everywhere else easy. If you do this as a service, you have room to expand, say in the case you want to start storing some data from the API in your own app.

    Anyway, cutting and posting from the linked documentation (the second link), the following shows how to send a GET to an API and how to set up handlers for success and failures, as well as dealing with request headers and query params — this should have everything you need.

    @Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0-RC2' )
    import groovyx.net.http.*
    import static groovyx.net.http.ContentType.*
    import static groovyx.net.http.Method.*
    
    def http = new HTTPBuilder( 'http://ajax.googleapis.com' )
    
    // perform a GET request, expecting JSON response data
    http.request( GET, JSON ) {
      uri.path = '/ajax/services/search/web'
      uri.query = [ v:'1.0', q: 'Calvin and Hobbes' ]
    
      headers.'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4'
    
      // response handler for a success response code:
      response.success = { resp, json ->
        println resp.statusLine
    
        // parse the JSON response object:
        json.responseData.results.each {
          println "  ${it.titleNoFormatting} : ${it.visibleUrl}"
        }
      }
    
      // handler for any failure status code:
      response.failure = { resp ->
        println "Unexpected error: ${resp.statusLine.statusCode} : ${resp.statusLine.reasonPhrase}"
      }
    }
    

    You might also want to check out this, for some nifty tricks. Is has an example with a POST method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing some named queries for my domain classes in Grails and I've hit
I am writing a Grails/Groovy app and I have a JSON object with a
I'm half way through writing my first grails app. It's going really well so
I'm writing a Grails app which I'd like 3rd parties to augment at runtime.
I am writing a web app in Grails with the Acegi/Spring Security plug-in, and
Writing an iPhone app in which I want to save the user the grief
I am writing a Grails app and I have a quick question about the
I'm writing a small Grails app, and I keep on getting StaleObjectStateException:s for about
I'm writing a web app using grails and spring-security 3.0.3 which requires me to
I'm writing an integration test in Grails using GORM. I want to do something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.