module JSONAPI::Parser
Parsing logic in rack middleware
Public Class Methods
parse_request(env)
click to toggle source
@param env [Hash] The rack envirornment hash @return [JSONAPI::Request] the instantiated jsonapi request object
# File lib/easy/jsonapi/parser.rb, line 15 def self.parse_request(env) req = Rack::Request.new(env) query_param_collection = RackReqParamsParser.parse(req.GET) header_collection = HeadersParser.parse(env) req_body = req.body.read # stored separately because can only read 1x req.body.rewind # rewind incase something else needs to read the body of the request document = includes_jsonapi_document?(env) ? DocumentParser.parse(req_body) : nil JSONAPI::Request.new(env, query_param_collection, header_collection, document) end
Private Class Methods
includes_jsonapi_document?(env)
click to toggle source
Is the content type jsonapi? @param (see parse_request) @return [TrueClass | FalseClass]
# File lib/easy/jsonapi/parser.rb, line 31 def self.includes_jsonapi_document?(env) env['CONTENT_TYPE'] == 'application/vnd.api+json' && env['REQUEST_METHOD'] != 'GET' end