Skip to content

Instantly share code, notes, and snippets.

@mike-neck
Last active August 29, 2015 14:04
Show Gist options
  • Save mike-neck/954bb5967b429806f056 to your computer and use it in GitHub Desktop.
Save mike-neck/954bb5967b429806f056 to your computer and use it in GitHub Desktop.
API叩くやつ
import groovyx.net.http.*
def http = new HTTPBuilder('http://localhost:8080/api/bookmarks/2')
http.request(Method.DELETE) {
response.success = {resp -> println 'ok'}
response.failure = {resp -> println 'ng'}
}
import groovyx.net.http.*
def http = new HTTPBuilder('http://localhost:8080/api/bookmarks/1')
http.request(Method.GET) {
def printContent = {content ->
new BufferedReader(new InputStreamReader(content)).eachLine {
println it.replaceAll('},'){'},\n'}
}
}
response.success = {resp ->
printContent(resp.entity.content)
}
response.failure = {resp ->
printContent(resp.entity.content)
}
}
import groovyx.net.http.*
def http = new HTTPBuilder('http://localhost:8080/api/bookmarks')
http.request(Method.GET) {
def printContent = {content ->
new BufferedReader(new InputStreamReader(content)).eachLine {
println it.replaceAll('},'){'},\n'}
}
}
response.success = {resp ->
printContent(resp.entity.content)
}
response.failure = {resp ->
printContent(resp.entity.content)
}
}
import groovyx.net.http.*
def http = new HTTPBuilder('http://localhost:8080/api/bookmarks')
http.request(Method.POST, ContentType.JSON) {
body = [
name : 'エンリコ・プッチ',
url : 'http://ja.wikipedia.org/wiki/エンリコ・プッチ'
]
def printContent = {content ->
new BufferedReader(new InputStreamReader(content)).eachLine {
println it.replaceAll('},'){'},\n'}
}
}
response.success = {resp ->
printContent(resp.entity.content)
}
response.failure = {resp ->
printContent(resp.entity.content)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment