开发者

RESTful API in CouchDB: How to structure your documents?

Since CouchDB is implementing a RESTful API, doesn't that mean I wanna put all documents of the same type in their own database?

eg.

POST http://localhost/users
GET http://localhost/users/1
PUT http://localhost/users/1
DELETE http://localhost/users/1

POST http://localhost/threads
GET http://localhost/threads/1
PUT http://localhost/threads/1
DELETE http://localhost/threads/1

Rather than putting them all in one big database (http://localhost/my_app).

Doesn't a 100% RESTful approach mean that the former 开发者_Python百科is more correct?


The primary reason to use multiple databases is to split the data up because of volume, notably creating new views, compaction, etc. There's no reason logically to split them up.

The simple truth is that the DB doesn't care. Nor do the URLs. Nor do REST. You can easily create a logically similar URL structure within couch using views, or if you find that offensive you can use the built in URL Rewriting functionality with Couch.

REST cares about architecture. REST cares that you use unique URLs. REST cares that you provides links to other resources via their URLs using hypermedia. REST cares that you use ubiquitous media types. Pretty URLs are way down on the list of things REST cares about.

If you want to do REST, focus on architecture and media-types. URLs pretty much handle themselves.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜