Module: Xenon::Routing::MarshallingDirectives

Includes:
RouteDirectives
Included in:
Directives
Defined in:
lib/xenon/routing/marshalling_directives.rb

Instance Method Summary collapse

Methods included from RouteDirectives

#complete, #extract, #extract_request, #fail, #map_request, #map_response, #reject

Instance Method Details

#body(as: nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/xenon/routing/marshalling_directives.rb', line 8

def body(as: nil)
  extract_request do |request|
    if as == IO
      yield request.body
    elsif as == String
      yield request.body.read
    else
      content_type = request.header('Content-Type')
      marshaller = Xenon::API.request_marshaller(content_type.content_type) # yuk
      yield marshaller.unmarshal(request.body, as: as)
    end
  end
end