- CouchDB and PHP Web Development Beginner’s Guide
- Tim Juravich
- 384字
- 2021-08-13 18:22:52
Time for action — creating new databases in CouchDB
In this exercise, we'll issue a PUT
request, which will create a new database in CouchDB.
- Create a new database by running the following command in Terminal:
curl -X PUT http://localhost:5984/test-db
- Terminal will respond with the following:
{"ok":true}
- Try creating another database with the same name by running the following command in Terminal:
curl -X PUT http://localhost:5984/test-db
- Terminal will respond with the following:
{"error":"file_exists","reason":"The database could not be created, the file already exists."}
- Okay, that didn't work. So let's to try to create a database with a different name by running the following command in Terminal:
curl -X PUT http://localhost:5984/another-db
- Terminal will respond with the following:
{"ok":true}
- Let's check the details of the
test-db
database quickly and see more detailed information about it. To do that, run the following command in Terminal:curl -X GET http://localhost:5984/test-db
- Terminal will respond with something similar to this (I re-formatted mine for readability):
{ "committed_update_seq": 1, "compact_running": false, "db_name": "test-db", "disk_format_version": 5, "disk_size": 4182, "doc_count": 0, "doc_del_count": 0, "instance_start_time": "1308863484343052", "purge_seq": 0, "update_seq": 1 }
What just happened?
We just used Terminal to trigger a PUT
method to the created databases through CouchDB's RESTful JSON API, by passing test-db
as the name of the database that we wanted to create at the end of the CouchDB root URL. When the database was successfully created, we received a message that everything went okay.
Next, we created a PUT
request to create another database with the same name test-db
. Because there can't be more than one database with the same name, we received an error message.
We then used a PUT
request to create a new database again, named another-db
. When the database was successfully created, we received a message that everything went okay.
Finally, we issued a GET
request to our test-db
database to find out more information on the database. It's not important to know exactly what each of these statistics mean, but it's a useful way to get an overview of a database.
It's worth noting that the URL that was called in the final GET
request was the same URL we called when we first created the database. The only difference is that we changed the HTTP method from PUT
to GET
. This is REST in action!
- Java逍遙游記
- 劍指JVM:虛擬機(jī)實(shí)踐與性能調(diào)優(yōu)
- Python高級編程
- Animate CC二維動(dòng)畫設(shè)計(jì)與制作(微課版)
- PhpStorm Cookbook
- 零基礎(chǔ)入門學(xué)習(xí)Python(第2版)
- 第一行代碼 C語言(視頻講解版)
- 編寫高質(zhì)量代碼:改善Objective-C程序的61個(gè)建議
- 并行編程方法與優(yōu)化實(shí)踐
- INSTANT Apache Hive Essentials How-to
- 金融商業(yè)數(shù)據(jù)分析:基于Python和SAS
- Extending Docker
- 美麗洞察力:從化妝品行業(yè)看顧客需求洞察
- C#網(wǎng)絡(luò)編程高級篇之網(wǎng)頁游戲輔助程序設(shè)計(jì)
- Getting Started with RethinkDB