summaryrefslogtreecommitdiff
path: root/server-rack.rb
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-11-21 15:15:01 -0700
committermo khan <mo.khan@gmail.com>2020-11-21 15:15:01 -0700
commita82b2fb5f4147a36959d1bfeb1e36cc114fc7423 (patch)
treee511b02662e9c8ecc81b20dfff5b94221464c580 /server-rack.rb
parentb10b1d0f1a4735a98160c028a28989539787b334 (diff)
feat: add DELETE /data/foo/:oid to remove blob from storage
Diffstat (limited to 'server-rack.rb')
-rw-r--r--server-rack.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/server-rack.rb b/server-rack.rb
index fbfd62a..2f22a4b 100644
--- a/server-rack.rb
+++ b/server-rack.rb
@@ -22,7 +22,7 @@ class DataStorageServer
# {object data}
# Objects that are not on the server will return a 404 Not Found.
def get(path)
- oid = path.split('/')[-1]
+ oid = id_from(path)
if @storage.key?(oid)
['200', {}, [@storage[oid]]]
else
@@ -37,6 +37,12 @@ class DataStorageServer
['201', {}, [JSON.generate({ size: data.size, oid: oid })]]
end
+ def destroy(path)
+ oid = id_from(path)
+ @storage.delete(oid)
+ ['200', {}, []]
+ end
+
def call(env)
path = env['PATH_INFO']
case env['REQUEST_METHOD']
@@ -44,10 +50,18 @@ class DataStorageServer
get(path)
when 'PUT'
put(env)
+ when 'DELETE'
+ destroy(path)
else
raise env.inspect
end
end
+
+ private
+
+ def id_from(path)
+ path.split('/')[-1]
+ end
end
# This starts the server if the script is invoked from the command line. No