Last active
August 29, 2015 14:04
-
-
Save mike-neck/954bb5967b429806f056 to your computer and use it in GitHub Desktop.
API叩くやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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