Module: Utopia::Controller::Respond::Converter::ToJSON
- Defined in:
- lib/utopia/controller/respond.rb
Overview
To accept incoming requests with content-type JSON (e.g. POST with JSON data), consider using ‘Rack::PostBodyContentTypeParser`.
Constant Summary collapse
- APPLICATION_JSON =
HTTP::Accept::ContentType.new('application/json', charset: 'utf-8').freeze
- HEADERS =
{HTTP::CONTENT_TYPE => APPLICATION_JSON.to_s}.freeze
Class Method Summary collapse
- .call(context, response, media_range) ⇒ Object
- .content_type ⇒ Object
- .serialize(content, media_range) ⇒ Object
- .split(*args) ⇒ Object
Class Method Details
.call(context, response, media_range) ⇒ Object
88 89 90 91 92 |
# File 'lib/utopia/controller/respond.rb', line 88 def self.call(context, response, media_range) Converter.update_response(response, HEADERS) do |content| self.serialize(content, media_range) end end |
.content_type ⇒ Object
70 71 72 |
# File 'lib/utopia/controller/respond.rb', line 70 def self.content_type APPLICATION_JSON end |
.serialize(content, media_range) ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/utopia/controller/respond.rb', line 78 def self.serialize(content, media_range) = {} if version = media_range.parameters['version'] [:version] = version.to_s end return content.to_json() end |
.split(*args) ⇒ Object
74 75 76 |
# File 'lib/utopia/controller/respond.rb', line 74 def self.split(*args) self.content_type.split(*args) end |