Advertisement
Guest User

Untitled

a guest
Jan 13th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. require "sinatra"
  2. require "sequel"
  3.  
  4. DB = Sequel.connect('postgres://localhost/blog', :user=>'admin', :password=>'5883328')
  5.  
  6. DB.create_table? :articles do
  7. primary_key :id
  8. String :title
  9. Text :content
  10. Integer :data_create
  11. end
  12.  
  13. class Article < Sequel::Model(:articles)
  14. end
  15.  
  16. get '/' do
  17. content_type :json
  18. Article.all.to_json
  19. end
  20.  
  21. get '/:id' do
  22. content_type :json
  23. Article[params(:id)].to_json
  24. end
  25.  
  26. post '/'
  27. Article.create params(:article) # it's no secure
  28. end
  29.  
  30. delete '/:id'
  31. Article[params(:id)].delete
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement