add dockerfile for isbn search
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,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…
Reference in New Issue