Class: Faraday::HalJson::Request

Inherits:
Middleware
  • Object
show all
Defined in:
lib/faraday/hal_json/request.rb

Overview

Request middleware that encodes the body as JSON.

Processes only requests with matching Content-type or those without a type. If a request doesn’t have a type but has a body, it sets the Content-type to JSON MIME-type.

Doesn’t try to encode bodies that already are in string form.

Constant Summary collapse

CONTENT_TYPE =
'Content-Type'
MIME_TYPE =
'application/hal+json'

Instance Method Summary collapse

Instance Method Details

#on_request(env) ⇒ Object



18
19
20
21
22
# File 'lib/faraday/hal_json/request.rb', line 18

def on_request(env)
  match_content_type(env) do |data|
    env[:body] = encode(data)
  end
end