Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Spruce up the README with more complete examples

  • Loading branch information...
commit 8cff7c1aa5a06b9cb1eba7438809daaa12781962 1 parent a2fc4aa
@vanstee authored
Showing with 96 additions and 8 deletions.
  1. +96 −8 README.md
View
104 README.md
@@ -5,29 +5,117 @@
Generate a RESTful API from a directory of ActiveRecord models.
+## Short Disclaimer
+
+I am not yet running this in production and the gem is not very
+extensible at this point. Consider it a proof of concept.
+
## Get Up and Running
1. Throw this in your Gemfile:
- `gem 'hovercraft'`
+ ```ruby
+ gem 'hovercraft'
+ ```
2. Put your ActiveRecord models in `models/` (make sure the file names
are the same as the class names).
+ Here's an example:
+
+ ```ruby
+ # models/employee.rb
+
+ class Employee < ActiveRecord::Base
+ attr_accessible :name, :career
+ end
+ ```
+
+ If you need help setting up an entire sinatra app here's a full
+ example: http://github.com/vanstee/hovercraft_example
+
3. Create a rackup file that generates the application:
```ruby
+ # config.ru
+
+ require 'bundler'
+ Bundler.require
+
run Hovercraft::Server.new
- ```
+ ```
+
+ If you need more setup I'd recommend using an `application.rb` file
+ and requiring that in the `config.ru` instead.
4. Run the application like normal:
- `bundle exec rackup`
+ ```
+ bundle exec rackup
+ ```
+
+5. Make some requests:
+
+ Create a record:
+
+ ```bash
+ curl -H 'Content-type: application/json' \
+ -X POST \
+ -d '{ "employee": { "name": "Philip J. Fry", "career": "Delivery Boy 1st Class" } }' \
+ http://localhost:9292/employees.json
+ ```
+
+ Show all records:
+
+ ```bash
+ curl http://localhost:9292/employees.json
+ ```
+
+ Show a single record:
+
+ ```bash
+ curl http://localhost:9292/employees/1.json
+ ```
+
+ Update a record:
+
+ ```bash
+ curl -H "Content-type: application/json" \
+ -X PUT \
+ -d '{ "employee": { "name": "Philip J. Fry", "career": "Executive Delivery Boy" } }' \
+ http://localhost:9292/employees/1.json
+ ```
+
+ Delete a record:
+
+ ```bash
+ curl -X DELETE http://localhost:9292/employees/1.json
+ ```
## Give Back
-1. Fork it
-2. Create your feature branch (`git checkout -b my-new-feature`)
-3. Commit your changes (`git commit -am 'Added some feature'`)
-4. Push to the branch (`git push origin my-new-feature`)
-5. Create new Pull Request
+1. Fork it:
+
+ https://help.github.com/articles/fork-a-repo
+
+2. Create your feature branch:
+
+ ```bash
+ git checkout -b fixes_horrible_spelling_errors
+ ```
+
+3. Commit your changes:
+
+ ```bash
+ git commit -am 'Really? You spelled application as "applickachon"?'
+ ```
+
+4. Push the branch:
+
+ ```bash
+ git push origin fixes_horrible_spelling_errors
+ ```
+
+5. Create a pull request:
+
+ https://help.github.com/articles/using-pull-requests
Please sign in to comment.
Something went wrong with that request. Please try again.