Bluemix の Cloudant に curl でアクセスする

Cloudant No SQL の説明に次の記述があります。
「Bluemix外部からRESTでDocumentを登録したり、削除したり、検索したりすることが出来ます。」
そこで、curl を使ってアクセスしてみました。

まず、Bluemix のコンソールで、URL を調べます。
「サービス資格情報」で「資格情報の表示」をクリックします。
JSON が表示されるので、その　"url":　という項目です。https:// で始まります。

データベースの作成　(URL は変更してあります。）

```bash
#
URL="https://44b508dd-346a-44c8-85b7-79d184aaf02f-bluemix:b92b6187dfe7c1fcb97c88ea2c0ce5015eee6829c5bb74fbb148e5aa8cfba362@18b508dd-346a-44c8-85b7-79d184aaf02f-bluemix.cloudant.com"
#
curl -X DELETE $URL/cities
curl -X PUT $URL/cities
curl -X PUT $URL/cities/tochigi -d@cities.json
curl -X GET $URL"/_all_dbs"
```

入力に使った　json ファイル

```json:cities.json
{
 "t0921":
 {"name": "宇都宮",
 "population": 84516,
 "date_mod": "2001-3-16"}
,
 "t0922":
 {"name": "小山",
 "population": 91237,
 "date_mod": "2001-4-21"}
,
 "t0923":
 {"name": "佐野",
 "population": 63489,
 "date_mod": "2001-5-21"}
,
 "t0924":
 {"name": "足利",
 "population": 72561,
 "date_mod": "2001-6-23"}
,
 "t0925":
 {"name": "日光",
 "population": 61743,
 "date_mod": "2001-9-21"}
,
 "t0926":
 {"name": "下野",
 "population": 52398,
 "date_mod": "2001-8-14"}
,
 "t0927":
 {"name": "さくら",
 "population": 45182,
 "date_mod": "2001-7-05"}
,
 "t0928":
 {"name": "矢板",
 "population": 37617,
 "date_mod": "2001-10-14"}
,
 "t0929":
 {"name": "真岡",
 "population": 52698,
 "date_mod": "2001-9-19"}
,
 "t0930":
 {"name": "栃木",
 "population": 47912,
 "date_mod": "2001-11-23"}
,
 "t0931":
 {"name": "大田原",
 "population": 52317,
 "date_mod": "2001-9-22"}
,
 "t0932":
 {"name": "鹿沼",
 "population": 62158,
 "date_mod": "2001-8-25"}
,
 "t0933":
 {"name": "那須塩原",
 "population": 82719,
 "date_mod": "2001-6-27"}
,
 "t0934":
 {"name": "那須烏山",
 "population": 38157,
 "date_mod": "2001-5-14"}
}
```

データの読み取り　(URL は変更してあります。）

```bash:go_get.sh
URL="https://44b508dd-346a-44c8-85b7-79d184aaf02f-bluemix:b92b6187dfe7c1fcb97c88ea2c0ce5015eee6829c5bb74fbb148e5aa8cfba362@18b508dd-346a-44c8-85b7-79d184aaf02f-bluemix.cloudant.com"
#
curl -X GET $URL"/cities/_all_docs"
echo ""
curl -X GET $URL"/cities/_all_docs?include_docs=true"
```

実行結果

```text
$ ./go_get.sh 
{"total_rows":1,"offset":0,"rows":[
{"id":"tochigi","key":"tochigi","value":{"rev":"1-a13cf7594e90572adfcfec76621886ee"}}
]}

{"total_rows":1,"offset":0,"rows":[
{"id":"tochigi","key":"tochigi","value":{"rev":"1-a13cf7594e90572adfcfec76621886ee"},"doc":{"_id":"tochigi","_rev":"1-a13cf7594e90572adfcfec76621886ee","t0921":{"name":"宇都宮","population":84516,"date_mod":"2001-3-16"},"t0922":{"name":"小山","population":91237,"date_mod":"2001-4-21"},"t0923":{"name":"佐野","population":63489,"date_mod":"2001-5-21"},"t0924":{"name":"足利","population":72561,"date_mod":"2001-6-23"},"t0925":{"name":"日光","population":61743,"date_mod":"2001-9-21"},"t0926":{"name":"下野","population":52398,"date_mod":"2001-8-14"},"t0927":{"name":"さくら","population":45182,"date_mod":"2001-7-05"},"t0928":{"name":"矢板","population":37617,"date_mod":"2001-10-14"},"t0929":{"name":"真岡","population":52698,"date_mod":"2001-9-19"},"t0930":{"name":"栃木","population":47912,"date_mod":"2001-11-23"},"t0931":{"name":"大田原","population":52317,"date_mod":"2001-9-22"},"t0932":{"name":"鹿沼","population":62158,"date_mod":"2001-8-25"},"t0933":{"name":"那須塩原","population":82719,"date_mod":"2001-6-27"},"t0934":{"name":"那須烏山","population":38157,"date_mod":"2001-5-14"}}}
```


#