Skip to content

Instantly share code, notes, and snippets.

@nicholashagen
Created May 23, 2013 14:26
Show Gist options
  • Save nicholashagen/5636470 to your computer and use it in GitHub Desktop.
Save nicholashagen/5636470 to your computer and use it in GitHub Desktop.
Groovy HTTPBuilder fails with GitHub
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.6' )
import groovyx.net.http.*
import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.URLENC
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
// this fails
try {
def github = new RESTClient( 'https://api.github.com' )
def resp = github.get( path : '/gists/public' )
assert resp.status == 200
assert resp.contentType == JSON.toString()
assert ( resp.data instanceof net.sf.json.JSON )
}
catch (e) { println e }
// this also fails
try {
def http = new HTTPBuilder('https://api.github.com')
http.get( path : '/gists/public',
contentType : JSON) { response, reader ->
assert resp.status == 200
}
}
catch (e) { println e }
// this works
new URL('https://api.github.com/gists/public').text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment