Sha256: b84329b9c45aa028e3d83c3acddbde7b51f3671551e9babebed8d835e1c3fc97

Contents?: true

Size: 642 Bytes

Versions: 3

Compression:

Stored size: 642 Bytes

Contents

require 'json'

module Hanami
  module Routing
    module Parsing
      class JsonParser < Parser
        def mime_types
          ['application/json', 'application/vnd.api+json']
        end

        # Parse a json string
        #
        # @param body [String] a json string
        #
        # @return [Hash] the parsed json
        #
        # @raise [Hanami::Routing::Parsing::BodyParsingError] when the body can't be parsed.
        #
        # @since 0.2.0
        def parse(body)
          JSON.parse(body)
        rescue JSON::ParserError => e
          raise BodyParsingError.new(e.message)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hanami-router-0.6.2 lib/hanami/routing/parsing/json_parser.rb
hanami-router-0.6.1 lib/hanami/routing/parsing/json_parser.rb
hanami-router-0.6.0 lib/hanami/routing/parsing/json_parser.rb