Closed ivanjaros closed 1 year ago
Here are some Axios examples that I have tested (and work for me):
import axios from 'axios';
import { decode, DecoderStream } from 'cbor-x';
let response = await axios({
url,
method: 'GET',
responseType: 'arraybuffer',
headers,
});
console.log('decoded arraybuffer data:', decode(response.data));
response = await axios({
url,
method: 'GET',
responseType: 'arraybuffer',
headers,
transformResponse: [decode],
});
console.log('decoded arraybuffer data with transformResponse:', response.data);
response = await axios({
url,
method: 'GET',
responseType: 'stream',
headers,
});
let decoderStream = new DecoderStream({ mapsAsObjects: true });
response.data.pipe(decoderStream);
decoderStream.on('data', (data) => console.log('decoded data from stream:', data));
await new Promise(r => decoderStream.on('end', r));
Are you also using cbor-x on the server side, or another package?
Thanks, but i have decided to not use cbor after all.
How do I use this with Axios? I am fiddling with response type setting to stream, arraybuffer, blob and trying do decode/encode in transformRequest and transformResponse methods of Axios client but cbor is not taking the data in.