@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.1.3') import org.apache.http.client.methods.* import org.apache.http.impl.client.* import groovy.json.* def _apikey = "your-key" def base = "https://api.mongohq.com/databases" def db = "mydb" def col = "employee" def doc_id = "your-document-id" def params = "_apikey=${_apikey}" def httpclient = new DefaultHttpClient() def method = new HttpGet("${base}/${db}/collections/${col}/documents/${doc_id}?${params}") response = httpclient.execute(method) println response.getStatusLine().getStatusCode() def content = new InputStreamReader( response.getEntity().getContent(), "UTF-8").text def json = new JsonSlurper().parseText(content) println json.employeeno println json.name
動作環境
groovy 1.8.6
関連情報
groovyとMongoDBのまとめ
0 件のコメント:
コメントを投稿