Simplest key-value store that is usable (I think). Uses the stdlib PStore for storage which is not suited to storing large pieces of data, but isn't that the point of a key-value store?
GET /
returns a json encoded array of keys (each as strings).
POST /
creates a new key-value pair
GET /:key
returns the value associated with the key
DELETE /:key
deletes the key (and value)
To play around with it I'm using the htty gem (gem install htty
).
$ ruby key_value.rb
$ htty http://0.0.0.0:4567
http://0.0.0.0:4567/> get
200 OK -- 4 headers -- 2-character body
http://0.0.0.0:4567/> body
[]
http://0.0.0.0:4567/> query-set key value
http://0.0.0.0:4567/?key=value> post
200 OK -- 3 headers -- 16-character body
http://0.0.0.0:4567/?key=value> query-clear
http://0.0.0.0:4567/> get
200 OK -- 4 headers -- 7-character body
http://0.0.0.0:4567/> body
["key"]
http://0.0.0.0:4567/> cd /key
http://0.0.0.0:4567/key> get
200 OK -- 4 headers -- 7-character body
http://0.0.0.0:4567/key> body
"value"
http://0.0.0.0:4567/key> delete
200 OK -- 4 headers -- 7-character body
http://0.0.0.0:4567/key> get
200 OK -- 4 headers -- 4-character body
http://0.0.0.0:4567/key> body
null
http://0.0.0.0:4567/key> cd /
http://0.0.0.0:4567/> get
200 OK -- 4 headers -- 2-character body
http://0.0.0.0:4567/> body
[]
http://0.0.0.0:4567/>
Yay, PStore! brilliant.