Module Grape::DSL::RequestResponse::ClassMethods
In: lib/grape/dsl/request_response.rb

Methods

Public Instance methods

Specify additional content-types, e.g.:

  content_type :xls, 'application/vnd.ms-excel'

All available content types.

Specify the default status code for errors.

Specify the default format for the API‘s serializers. May be `:json` or `:txt` (default).

Specify the format for the API‘s serializers. May be `:json`, `:xml`, `:txt`, etc.

Specify a custom formatter for a content-type.

Specify a custom parser for a content-type.

Allows you to specify a default representation entity for a class. This allows you to map your models to their respective entities once and then simply call `present` with the model.

@example

  class ExampleAPI < Grape::API
    represent User, with: Entity::User

    get '/me' do
      present current_user # with: Entity::User is assumed
    end
  end

Note that Grape will automatically go up the class ancestry to try to find a representing entity, so if you, for example, define an entity to represent `Object` then all presented objects will bubble up and utilize the entity provided on that `represent` call.

@param model_class [Class] The model class that will be represented. @option options [Class] :with The entity class that will represent the model.

Allows you to rescue certain exceptions that occur to return a grape error rather than raising all the way to the server level.

@example Rescue from custom exceptions

    class ExampleAPI < Grape::API
      class CustomError < StandardError; end

      rescue_from CustomError
    end

@overload rescue_from(*exception_classes, **options)

  @param [Array] exception_classes A list of classes that you want to rescue, or
    the symbol :all to rescue from all exceptions.
  @param [Block] block Execution block to handle the given exception.
  @param [Hash] options Options for the rescue usage.
  @option options [Boolean] :backtrace Include a backtrace in the rescue response.
  @option options [Boolean] :rescue_subclasses Also rescue subclasses of exception classes
  @param [Proc] handler Execution proc to handle the given exception as an
    alternative to passing a block.

[Validate]