File tree 2 files changed +39
-0
lines changed
tagging-and-versioning/versioning
2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ FROM ruby:2.4.1-alpine
2
+ RUN mkdir /app
3
+ WORKDIR /app
4
+ RUN gem install sinatra sinatra-contrib
5
+ COPY . .
6
+ EXPOSE 3000
7
+ CMD ruby server.rb
Original file line number Diff line number Diff line change
1
+ require 'sinatra'
2
+ require 'sinatra/namespace'
3
+ require 'json'
4
+
5
+ set :bind , '0.0.0.0'
6
+ set :port , 3000
7
+
8
+ class Book
9
+ def initialize ( title , author , isbn )
10
+ @title = title
11
+ @author = author
12
+ @isbn = isbn
13
+ end
14
+ attr_accessor :title
15
+ attr_accessor :author
16
+ attr_accessor :isbn
17
+ def to_json
18
+ { 'title' => @title , 'author' => @author , 'isbn' => @isbn } . to_json
19
+ end
20
+ end
21
+
22
+ get '/' do
23
+ 'Welcome to BookList!'
24
+ end
25
+
26
+ namespace '/api/v1' do
27
+ get '/books' do
28
+ isbn = params [ :isbn ]
29
+ book = Book . new ( 'Foundation' , 'Isaac Asimov' , isbn )
30
+ book . to_json
31
+ end
32
+ end
You can’t perform that action at this time.
0 commit comments