lib/grape/api.rb
# Defines a route that will be recognized
# by the Grape API.
#
# @param methods [HTTP Verb] One or more HTTP verbs that are accepted by this route. Set to `:any` if you want any verb to be accepted.
# @param paths [String] One or more strings representing the URL segment(s) for this route.
#
# @example Defining a basic route.
#   class MyAPI < Grape::API
#     route(:any, '/hello') do
#       {:hello => 'world'}
#     end
#   end
Defines a route that will be recognized
by the Grape API.
Defines a route that will be recognized by the Grape API .
def route(methods, paths = ['/'], route_options = {}, &block)
        endpoint_options = {
          :method => methods,
          :path => paths,
          :route_options => (@namespace_description || {}).deep_merge(@last_description || {}).deep_merge(route_options || {})
        }
        endpoints << Grape::Endpoint.new(settings.clone, endpoint_options, &block)
        @last_description = nil
        reset_validations!
      end
def route ( methods , paths = [ '/' ] , route_options = { } , & block ) endpoint_options = { :method => methods , :path => paths , :route_options => ( @namespace_description || { } ) . deep_merge ( @last_description || { } ) . deep_merge ( route_options || { } ) } endpoints << Grape :: Endpoint . new ( settings . clone , endpoint_options , & block ) @last_description = nil reset_validations! end
Defines a route that will be recognized
by the Grape API.
Defines a route that will be recognized by the Grape API .
methods
One or more HTTP verbs that are accepted by this route. Set to `:any` if you want any verb to be accepted.
One or more HTTP verbs that are accepted by this route . Set to ` : any ` if you want any verb to be accepted .
paths
One or more strings representing the URL segment(s) for this route.
One or more strings representing the URL segment ( s ) for this route .
route_options
<not_specific>
block
<not_specific>
example
Defining a basic route. class MyAPI < Grape::API route(:any, '/hello') do {:hello => 'world'} end end
Defining a basic route . class MyAPI < Grape :: API route ( : any ' / hello ' ) do { : hello = > ' world ' } end end