RESTful API in CouchDB: how to structure your documents?

Since CouchDB implements a RESTful API, does this mean that I want to put all documents of the same type into my 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 

Instead of putting them in one big database (http: // localhost / my_app).

Does a 100 percent RESTful approach mean that the former is more correct?

+4
source share
1 answer

The main reason for using multiple databases is to split the data due to the volume, in particular to create new views, compact, etc. There are no reasons to logically separate them.

The simple truth is that the database does not care. URLs are also not used. Also no REST. You can easily create a logically similar URL structure inside the couch using views, or if you find it offensive, you can use the built-in URL rewriting features with Couch.

REST takes care of architecture. REST makes sure that you use unique URLs. REST makes sure that you provide links to other resources through your URLs using hypermedia. REST makes sure you use the ubiquitous types of media. Pretty URLs in the list of things REST cares about.

If you want to do REST, focus on architecture and media types. URLs do it all by themselves.

+11
source

All Articles