Method: Grape::DSL::RequestResponse::ClassMethods#format

Defined in:
lib/grape/dsl/request_response.rb

#format(new_format = nil) ⇒ Object

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



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/grape/dsl/request_response.rb', line 19

def format(new_format = nil)
  if new_format
    namespace_inheritable(:format, new_format.to_sym)
    # define the default error formatters
    namespace_inheritable(:default_error_formatter, Grape::ErrorFormatter.formatter_for(new_format, {}))
    # define a single mime type
    mime_type = content_types[new_format.to_sym]
    raise Grape::Exceptions::MissingMimeType.new(new_format) unless mime_type
    namespace_stackable(:content_types, new_format.to_sym => mime_type)
  else
    namespace_inheritable(:format)
  end
end