4 ms·
Why the wacky SET/GET? Why not being restful and using HTTP verbs?
by reshefm 16y ago
Why the wacky SET/GET?
Why not being restful and using HTTP verbs?
- antirez 16y agoProbably since in Redis there are a multitude of write and read operations, so anyway a good HTTP protocol "map" is not possible.
- eterps 16y agoI agree, why on earth would somebody set something with a GET request?
- jsarch 16y agoIf you separate the syntax from the semantics, you'll see that the GET request (syntax) is merely the mechanism of accessing the appropriate function (semantics). If you reread the short article after deleting all the junk about REST and CouchDB, and ignore the presumption that this is a RESTful API, then the article is clearer: Webdis is an HTTP interface to Redis.
- eterps 16y agoHmmm, you're right. The bit about REST and CouchDB is a bit misleading.
- kbd 16y agoBecause there are a LOT more commands[1] than "set", "get", and "del". http://redis.io/commands http://redis.io/commands
- eterps 16y agoSo? REST does not limit the amount of operations you can do on resources.
- kbd 16y agoYou must've misread somewhere. The OP said "Why not being restful and using HTTP verbs?" I said "because there are far more commands than HTTP verbs". In other words, this has nothing to do with "the amount of operations you can do with rest", this has to do with not being able to use the limited number of HTTP verbs to correspond to the multitude of Redis commands.
- thamer 16y ago(I'm the author of Webdis) I agree with you, and to be honest this is what bothers me the most in the current state of the project. The top point in the list of TODO/IDEAS is currently “Add better support for PUT, DELETE, HEAD, OPTIONS? How? For which commands?”. I'd be very glad to hear about a better way to implement this. As antirez (author of Redis) and kbd pointed out, Redis supports a lot more than GET/SET. How do I make LPUSH/RPUSH/SADD... RESTful?
- fedd 16y agowhy SET, maybe POST?
- patrickaljord 16y agoI think any command that modifies and writes to the DB should be POST or PUT (for editing existing entries), what reads should be GET and anything that delete should be DELETE?
- shazow 16y agoPlease please please do not make the API dependent on HTTP method verbs. This completely breaks JavaScript apps[1] and it's an arbitrary constraint that does not benefit anything except REST zealotry. [1] For example, cross-domain JavaScript requests can only read GET responses.
- thamer 16y agoI think there should be a way to disable GET for some commands, this seems to be a serious concern. That said, you'll always be able to access Webdis using GET; you present a common case that justifies the existence of such a feature. I have started to implement Cross-Origin Resource Sharing, which should enable cross-domain JS requests using POST (If I understood correctly). An OPTIONS call is made by the client before the POST.
- davidmathers 16y agoHi thamer, your question made me curious so I decided to see what I could come up with. I've never used redis so this might be all whack, but here's what I did with the list type after looking at the redis docs: Type operations: POST /list?key=<key>&value=<value> -> LPUSH DELETE /list?timeout=<timeout>&key[0]=<key>&key[1]=<key> -> BLPOP List operations: POST /list/<key>?value=<value> -> LPUSHX DELETE /list/<key> -> LPOP Search based operations: POST /list/<key>?find=<value>&value=<value> -> LINSERT BEFORE DELETE /list/<key>?find=<value>&count=<count> -> LREM Index based operations: GET /list/<key>/<index> -> LINDEX GET /list/<key>/<index>?count=<count> -> LRANGE PUT /list/<key>/<index>?value=<value> -> LSET Transactional operations: POST /list-tx/rpop/push?source=<key>&target=<key> -> RPOPLPUSH POST /list-tx/rpop/push?timeout=<timeout>&source=<key>&target=<key> -> BRPOPLPUSH Length GET /list-length/<key> -> LLEN Reverse operations: POST /rlist?key=<key>&value=<value> -> RPUSH POST /rlist/<key>?value=<value> -> RPUSHX DELETE /rlist/<key> -> RPOP POST /rlist/<key>?find=<value>&value=<value> -> LINSERT AFTER DELETE /rlist?timeout=<timeout>&key[0]=<key>&key[1]=<key> -> BRPOP