-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
59 lines (42 loc) · 814 Bytes
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'sinatra'
require 'mongoid'
require 'oj'
require "sinatra/reloader" if development?
Mongoid.load!('mongoid.yml')
class Doc
include Mongoid::Document
field :name_first, type: String
# embeds_many :street_address
end
# class StreetAddress
# include Mongoid::Document
# field :street, type: String
# embedded_in :doc
# end
get '/' do
content_type :json
doc = Doc.all
doc.to_json
end
get '/:id' do
content_type :json
doc = Doc.find params[:id]
doc.to_json
end
#create
post '/' do
data=JSON.parse(request.body.read)["resume"]
doc = Doc.create!(data)
doc.to_json
end
#update
put '/:id' do
data=JSON.parse(request.body.read)["resume"]
doc = Doc.find params[:id]
doc.update_attributes!(data)
end
# #destroy
delete '/:id' do
doc = Doc.find params[:id]
doc.destroy
end