Class: Webmachine::Request

Inherits:
Object
  • Object
show all
Includes:
URIReplacement
Defined in:
lib/eipiai/resources/ext/webmachine/request.rb

Overview

Request

Defined Under Namespace

Modules: URIReplacement

Instance Method Summary collapse

Methods included from URIReplacement

#build_uri

Instance Method Details

#json?true, false

json?

returns ‘true` if the Content-Type header is of type `application/json`.

Examples:

Content-Type: application/json

post('/items', '{}', 'Content-Type': 'application/json')
resource.request.json? # => true

Content-Type: application/json; charset=utf-8

post('/items', '{}', 'Content-Type': 'application/json; charset=utf-8')
resource.request.json? # => true

unset Content-Type header

post('/items', '{}')
resource.request.json? # => false

Returns:

  • (true, false)


29
30
31
32
33
# File 'lib/eipiai/resources/ext/webmachine/request.rb', line 29

def json?
  return false unless content_type

  Webmachine::MediaType.parse(content_type).type_matches?('application/json')
end