Skip to content

Refactor or remove Response#parse API #538

@ixti

Description

@ixti

IMO Response#parse with implicit MIME-type guessed from response Content-Type must be discouraged:

HTTP.get("http://example.com").parse

The snippet above will raise:

HTTP::Error: Unknown MIME type: text/html

Although error message is clear, I don't see how this API can be good to use. Let's say one will define parser for text/html that will be returning Nokogiri::Document. So now, #parse will be returning Nokogiri::Document if content type is text/html, Array or Hash if content type is application/json... There's no way one will be able to work with that without some sort of wrapper (or just branching based on type) to neglect differences between Nokogiri::Document and plain Array or Hash loaded from JSON.

So probably we should make mime type argument required.

PS Users of Oj may find this API less performant than Oj.load(res) as latter one will utilize streaming.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions