Skip to content

Commit

Permalink
Removes Entities from README and adds link to Frontier. Defaults vers…
Browse files Browse the repository at this point in the history
…ioning to path.
  • Loading branch information
Michael Bleigh committed Dec 5, 2011
1 parent e536bde commit 0529e92
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 36 deletions.
38 changes: 3 additions & 35 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Grape
[![Build Status](http://travis-ci.org/intridea/grape.png)](http://travis-ci.org/intridea/grape)
# Grape [![Build Status](http://travis-ci.org/intridea/grape.png)](http://travis-ci.org/intridea/grape)

**Note:** This is the `master` branch of Grape where we're trying to maintain things to be relatively stable. If you want to live on the edge, check out the [frontier](https://github.com/intridea/grape/tree/frontier).

Grape is a REST-like API micro-framework for Ruby. It is built to complement existing web application frameworks such as Rails and Sinatra by providing a simple DSL to easily provide APIs. It has built-in support for common conventions such as multiple formats, subdomain/prefix restriction, and versioning.

Expand Down Expand Up @@ -116,39 +117,6 @@ class API < Grape::API
end
````


## Working with Entities

A common problem in designing Ruby APIs is that you probably don't want
the exact structure of your data models exposed. ActiveRecord, for
instance, will dump all of its attributes. While you can override
`#as_json` to alter this behavior somewhat, what is really needed is an
intermediary layer between the model and the API. This is where the
`Grape::Entity` class comes in.

```ruby
module Entities
class User < Grape::Entity
expose :first_name, :last_name
expose :email, :if => {:authenticated => true}
expose :name, :id => {:version => 'v1'} # deprecated
end
end

class API < Grape::API
version 'v1', 'v2'

get '/users/:id' do
present User.find(params[:id]),
:with => Entities::User,
:authenticated => env.key?('api.token')
end
end
```

For more information about Entities, view the project's YARD
documentation.

## Raising Errors

You can raise errors explicitly.
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def version(*args, &block)
if args.any?
options = args.pop if args.last.is_a? Hash
options ||= {}
options = {:using => :header}.merge!(options)
options = {:using => :path}.merge!(options)
@versions = versions | args
nest(block) do
set(:version, args)
Expand Down

0 comments on commit 0529e92

Please sign in to comment.