-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add support for responseType option #376
base: main
Are you sure you want to change the base?
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
On one hand it is true. Users calling are made aware of possible return types. This, however, brings no guarantees what is going to be returned. With this changeset, it would be possible to make a mistake (or force an error) by requesting In terms of type safety, users in such need, will need perform type refinement in order to make sure if the returned value is of that instance anyway. Yes, it would be possible to have a small shim on top of it that adds some type "safety", e.g.: getArrayBuffer(path: string, request?: GetRequest<CO>): Promise<ArrayBuffer> {
return this.get<ArrayBuffer>(path, {responseType: 'arraybuffer', ...request});
} but it would still be wishful thinking. What I still have not grasped in Axios' approach, is why indeed it's not relying on headers. Content negotiation is a big part of the web. It provides a well-defined flow for how client-server communication works. This is where this library drops the ball. The standard is that anything that is not human readable and contains binary data shouldn't be treated as If I had any say in this project (which I don't) I would prefer it would pay closer attention to content negotiation. This could allow for non-JSON, non-text responses to be provided to the user. |
Hello,
This is my first contribution in my life to Open Source project. Please be kind.
In this PR you can find my approach to tackling #29 -- My project needed to get the data as ArrayBuffer from a PDF Document fetcher API, that is why I used it as an example case in read me file.
I took the similar approach as Axios instead of relying on headers, as personally I think this has better type safety and is more transparent to consumers of the library.