| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Generate a RESTful API from a directory of ActiveRecord models.
I am not yet running this in production and the gem is not very extensible at this point. Consider it a proof of concept.
Throw this in your Gemfile:
gem 'hovercraft'Put your ActiveRecord models in models/ (make sure the file names are the same as the class names).
Here's an example:
# models/employee.rb
class Employee < ActiveRecord::Base
attr_accessible :name, :career
endIf you need help setting up an entire sinatra app here's a full example: http://github.com/vanstee/hovercraft_example
Create a rackup file that generates the application:
# config.ru
require 'bundler'
Bundler.require
run Hovercraft::Server.newIf you need more setup I'd recommend using an application.rb file and requiring that in the config.ru instead.
Run the application like normal:
bundle exec rackup
Make some requests:
Create a record:
curl -H 'Content-type: application/json' \
-X POST \
-d '{ "employee": { "name": "Philip J. Fry", "career": "Delivery Boy 1st Class" } }' \
http://localhost:9292/employees.jsonShow all records:
curl http://localhost:9292/employees.jsonShow a single record:
curl http://localhost:9292/employees/1.jsonUpdate a record:
curl -H "Content-type: application/json" \
-X PUT \
-d '{ "employee": { "name": "Philip J. Fry", "career": "Executive Delivery Boy" } }' \
http://localhost:9292/employees/1.jsonDelete a record:
curl -X DELETE http://localhost:9292/employees/1.jsonInclude warden in your Gemfile:
gem 'warden'Use rack builder to add warden strategies to your rackup file:
# config.ru
require 'bundler'
Bundler.require
application = Rack::Builder.new do
use Rack::Session::Cookie, secret: '...'
Warden::Strategies.add :password do
def valid?
...
end
def authenticate
...
end
end
use Warden::Manager do |manager|
manager.default_strategies :password
manager.failure_app = ...
end
run Hovercraft::Server
end
run applicationSee the warden project for more in-depth examples or help troubleshooting.
Fork it:
Create your feature branch:
git checkout -b fixes_horrible_spelling_errorsCommit your changes:
git commit -am 'Really? You spelled application as "applickachon"?'Push the branch:
git push origin fixes_horrible_spelling_errorsCreate a pull request:
| Back | FazBrowse Home | New Git URL |