Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTful API in CouchDB: How to structure your documents?

Tags:

rest

couchdb

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 is more correct?

like image 489
ajsie Avatar asked Dec 22 '22 11:12

ajsie


1 Answers

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.

like image 157
Will Hartung Avatar answered Jan 17 '23 05:01

Will Hartung