---
title: "Make a HTTP Call From a Groovy Script"
canonical: "https://support.appfire.com/space/JMWE/461406951/Make%20a%20HTTP%20Call%20From%20a%20Groovy%20Script"
format: markdown
---
> Macro (aura-html)

### Abstract

<span style="color: #091e42">This code snippet makes an HTTP call </span><span style="color: #172b4d">and processes the returned data</span><span style="color: #091e42">.</span>

### Logic

- <span style="color: #091e42">Import the HTTPBuilder and the request methods.</span>
- <span style="color: #091e42">Make an HTTP by creating a new HTTP instance.</span>
- <span style="color: #091e42">Request the data passing the respective method, the content type, and the request configuration closure to the request method.</span>
- <span style="color: #091e42">Return the parsed data from the response.</span>

### Snippet 

```groovy
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.<methodName>
import static groovyx.net.http.ContentType.<contentType>
 
// initialize a new builder and give a default URL
def http = new HTTPBuilder("<URL>")
 
def data = http.request(<methodName>,<contentType>) { req ->
 
  response.success = { resp, reader ->
    assert resp.status == 200
	return reader
  }
 
  // called only for a 404 (not found) status code:
  response."404" = { resp ->
    log.error ("Not found")
  }
}

if (data) {
  // process returned data
}
```

##### Placeholders

| Placeholder | Description | Example |
| --- | --- | --- |
| `<URL`> | `URL` | [https://www.google.com/](https://www.google.com/) |
| `<methodName>` | `Name of the request method` | `GET` |
| `<contentType>` | `Type of the content requested for` | `TEXT` |

### Context

<span style="color: #333333">The outcome of the code snippet depends on the </span><span style="color: #091e42">content type passed to the request method.</span><span style="color: #333333"> You could use this code, for example, to get a specific currency conversion rate.</span>

### Example

To get the HTML text an issue view page, you can use this snippet to make the HTTP call, get the content and parse it.

```groovy
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.TEXT
 
// initialize a new builder and give a default URL
def http = new HTTPBuilder("https://www.google.com/")
 
return http.request(GET,TEXT) { req ->
  response.success = { resp, htmlText ->
    assert resp.status == 200
    log.debug("My response handler got response: ${resp.statusLine}")
    if(htmlText){
     return htmlText.getText()
    }
    else{
      return null
    }
  }
 
  // called only for a 404 (not found) status code:
  response."404" = { resp ->
    log.error ("Not found")
    return null
  }
}
```

### Reference

- **[HTTPBuilder](https://github.com/jgritman/httpbuilder/wiki)**
- **[Groovy Documentation](http://groovy.codehaus.org/User+Guide)**

### Related articles

> Macro (contentbylabel)