1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
module Spec
module Support
# Test API
class API < Grape::API::Instance
version 'v1'
prefix 'api'
format 'json'
get 'custom_name', as: :my_custom_route_name do
'hello'
end
get 'ping' do
'pong'
end
resource :cats do
get '/' do
%w[cats cats cats]
end
route_param :id do
get do
'cat'
end
end
get ':id/(-/)optional' do
'optional content'
end
get ':id/owners' do
%w[owner1 owner2]
end
get ':id/owners/:owner_id' do
'owner'
end
get ':id/owners/*owner_ids/cats' do
%w[cats cats cats]
end
end
route :any, '*path' do
'catch-all route'
end
end
# API with more than one version
class APIWithMultipleVersions < Grape::API::Instance
version %w[beta alpha v1]
get 'ping' do
'pong'
end
end
# API with another API mounted inside it
class MountedAPI < Grape::API::Instance
mount Spec::Support::API
mount Spec::Support::APIWithMultipleVersions
end
# API with a version that would be illegal as a method name
class APIWithIllegalVersion < Grape::API::Instance
version 'beta-1'
get 'ping' do
'pong'
end
end
# API with multiple POST routes
class MultiplePostsAPI < Grape::API::Instance
resource :hamlet do
post 'to_be' do
end
post 'or_not_to_be' do
end
end
end
class BaseAPI < Grape::API::Instance
end
class DerivedAPI < BaseAPI
get 'derived_ping' do
'pong'
end
end
end
end
|