Skip to content

Commit

Permalink
update readme file with example usage for mounting multiple version i…
Browse files Browse the repository at this point in the history
  • Loading branch information
przbadu committed Mar 8, 2016
1 parent d718708 commit 2d4a8e8
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- [Header](#header)
- [Accept-Version Header](#accept-version-header)
- [Param](#param)
- [Mounting multiple versions](#mounting-multiple-versions)
- [Describing Methods](#describing-methods)
- [Parameters](#parameters)
- [Declared](#declared)
Expand Down Expand Up @@ -390,6 +391,71 @@ version 'v1', using: :param, parameter: 'v'

curl http://localhost:9292/statuses/public_timeline?v=v1

## Mounting multiple versions

Example directory structure.


|- api/
|-- api.rb
|-- v1/
|--- api.rb
|-- v2/
|--- api.rb


`api/api.rb`

```ruby
class API < Grape::API
prefix 'api'
version ['v2', 'v1']
format :json
default_format :json

mount V2::API
mount V1::API
end
```

`api/v1/api.rb`

```ruby
class V1::API < Grape::API
version 'v1' # required block even version ['v2', 'v1'] included in api.rb
# If you miss version block here, then
# /api/v1/test/first and
# /api/v2/test/first
# both will return 'v2 API' response, regardless of what version you supplied in the url.

resource :test do
get do
'v1 API'
end
end
end
```

`api/v2/api`

```ruby
class V2::API < Grape::API
version 'v2' # required block even version ['v2', 'v1'] included in api.rb

resource :test do
get do
'v2 API'
end
end
end
```

Finally:

curl http://localhost:3000/api/v2/test
# => "v1 API"
curl http://localhost:3000/api/v1/test
# => "v2 API"

## Describing Methods

Expand Down

0 comments on commit 2d4a8e8

Please sign in to comment.