summaryrefslogtreecommitdiff
path: root/server-rack.rb
diff options
context:
space:
mode:
authorinterview-bot-ng[bot] <46227427+interview-bot-ng[bot]@users.noreply.github.com>2020-11-21 21:40:35 +0000
committerGitHub <noreply@github.com>2020-11-21 21:40:35 +0000
commit8f679cee1192d216065ed82393f4625c9e4dfb70 (patch)
tree6bcd5fe6bfedaaa027c098a2de20181619c3fa09 /server-rack.rb
parent698008851b98800a942dfd2417ef946465889d6b (diff)
Import of the exercise.HEADmain
Diffstat (limited to 'server-rack.rb')
-rw-r--r--server-rack.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/server-rack.rb b/server-rack.rb
new file mode 100644
index 0000000..b73f4da
--- /dev/null
+++ b/server-rack.rb
@@ -0,0 +1,45 @@
+#!/usr/bin/env ruby
+# Usage:
+#
+# $ ruby rack-server.rb
+require 'rack'
+require 'json'
+
+class DataStorageServer
+ # You may initialize any variables you want to use across requests here
+ def initialize
+ @storage = {}
+ end
+
+ # Download an Object
+ #
+ # GET /data/{repository}/{objectID}
+ # Response
+ #
+ # Status: 200 OK
+ # {object data}
+ # Objects that are not on the server will return a 404 Not Found.
+ def get(path)
+ ['200', {}, ["hello from get #{path}"]]
+ end
+
+
+ def call(env)
+ path = env['PATH_INFO']
+ case env['REQUEST_METHOD']
+ when 'GET'
+ get(path)
+ end
+ end
+end
+
+# This starts the server if the script is invoked from the command line. No
+# modifications needed here.
+if __FILE__ == $0
+ app = Rack::Builder.new do
+ use Rack::Reloader
+ run DataStorageServer.new
+ end.to_app
+
+ Rack::Server.start(app: app, Port: 8282)
+end \ No newline at end of file