Skip to content

Avoid automated json conversion when using fetch #947

Description

@daffl

From @eric-burel on June 8, 2018 8:32

Hi,

I noticed that the fetch service always does a response.json(), however in many case you might need another conversion (e.g response.blob() for files). For the moment, reading the code, I think this can't be configured (tell me if I am wrong though), that could be a good enhancement.

However I wonder what would be the best pattern. Having response.json as a default makes sense, as it is consistent with other solutions (axios etc.).

The potential solutions:

  • figuring out the best option depending on the mime type. I think it only partially solve the issue, as I could still want my image as a string and not a blob() for example, and would be tedious to implement.
  • adding a custom parameter to tell fetch what to use. responseType is a good candidate, as it would be consistent with XHR (so axios too and maybe other services).

Edit: actually I can't figure this out either for axios, the responseType does not seem to be customizable.
Edit 2: okay I figured out your last commit now allow this for Axios, I needed to update the lib.

Copied from original issue: feathersjs-ecosystem/rest-client#32

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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