lib/auto_api/base.rb in auto_api-0.0.6 vs lib/auto_api/base.rb in auto_api-0.0.7
- old
+ new
@@ -8,10 +8,12 @@
class AutoApi::Base < Sinatra::Base
configure :development do
register Sinatra::Reloader
end
+ disable :protection
+
Mongoid.load!('./config/mongoid.yml')
# WE ARE RETURNING JSON
before '/*' do
content_type 'application/json'
@@ -41,20 +43,20 @@
webtry { json @resource.find(id) }
end
post '/:resource/?' do |resource|
webtry do
- resource = @resource.new(request.params)
+ resource = @resource.new(JSON.parse request.body.read)
resource.save!
json resource
end
end
put '/:resource/:id/?' do |resource, id|
webtry do
resource = @resource.find(id)
- resource.update_attributes!(request.params)
+ resource.update_attributes!(JSON.parse request.body.read)
end
end
delete '/:resource/:id/?' do |_resource, id|
webtry { json @resource.find(id).delete }
@@ -70,10 +72,10 @@
end
post '/:resource1/:id1/:resource2/?' do |_resource1, id1, resource2|
webtry do
parent_resource = @resource1.find(id1)
- child_resource = @resource2.new(request.params)
+ child_resource = @resource2.new(JSON.parse request.body.read)
child_resource.save!
parent_resource.send(resource2) << child_resource
json child_resource
end
end