add dockerfile for isbn search

trunk
Thomas Riboulet 3 years ago
parent d5c2f278f2
commit f8be3938f6

@ -0,0 +1,11 @@
from ruby:3.0.2
RUN mkdir /var/app
WORKDIR /var/app
COPY . .
RUN bundle install
CMD ["sh", "bin/http"]

@ -1,4 +1,6 @@
source 'https://rubygems.org'
gem 'sinatra'
gem 'rack', '~> 2.0.1'
gem 'thin'
gem 'thin'
gem 'byebug'

@ -1,6 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
byebug (11.1.3)
daemons (1.4.1)
eventmachine (1.2.7)
mustermann (1.1.1)
@ -24,6 +25,7 @@ PLATFORMS
arm64-darwin-20
DEPENDENCIES
byebug
rack (~> 2.0.1)
sinatra
thin

@ -1,6 +1,34 @@
# app.rb
require 'sinatra'
require 'json'
ISBNS = {
'2-7654-1005-4': {
title: 'Lucy',
author: 'Renard',
description: 'A book about stars.'
},
'2-7754-1105-4': {
title: 'Mountains',
author: 'John Smith',
description: 'A book about plains.'
},
}
get '/' do
'Hello world!'
end
get '/isbn/:isbn' do
isbn = params[:isbn].to_sym
if ISBNS.keys.include?(isbn)
response = ISBNS[isbn].to_json
status 200
body response
else
response = { error: 'Not found' }.to_json
status 404
body response
end
end

Loading…
Cancel
Save