Module Grape::DSL::Routing::ClassMethods
In: lib/grape/dsl/routing.rb

Methods

Attributes

endpoints  [R] 

Public Instance methods

Do not route HEAD requests to GET requests automatically.

Do not automatically route OPTIONS.

group(space = nil, options = {}, &block)

Alias for namespace

Declare a "namespace", which prefixes all subordinate routes with its name. Any endpoints within a namespace, or group, resource, segment, etc., will share their parent context as well as any configuration done in the namespace context.

@example

    namespace :foo do
      get 'bar' do
        # defines the endpoint: GET /foo/bar
      end
    end

Define a root URL prefix for your entire API.

Remove all defined routes.

resource(space = nil, options = {}, &block)

Alias for namespace

resources(space = nil, options = {}, &block)

Alias for namespace

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

Thie method allows you to quickly define a parameter route segment in your API.

@param param [Symbol] The name of the parameter you wish to declare. @option options [Regexp] You may supply a regular expression that the declared parameter must meet.

An array of API routes.

Create a scope without affecting the URL.

@param _name [Symbol] Purely placebo, just allows to name the scope to make the code more readable.

segment(space = nil, options = {}, &block)

Alias for namespace

Specify an API version.

@example API with legacy support.

  class MyAPI < Grape::API
    version 'v2'

    get '/main' do
      {some: 'data'}
    end

    version 'v1' do
      get '/main' do
        {legacy: 'data'}
      end
    end
  end

@return array of defined versions

[Validate]