I would like to ask you for help with REST API in Node / Express.
I'm calling a vendor API to get a label in PDF format, and then I need to send it to a user which is calling the API.
I'm using the request
npm package to call another API. I have also tried node-fetch
but with no luck.
Example code:
retrieveLabel(req, res, next) {
const options = {
method: 'GET',
url: 'apiUrl' + 'shipments/xxx/label',
headers: {
'cache-control': 'no-cache',
authorization: xxxToken,
'content-type': 'application/json'
}
};
request(options, (error, response, results) => {
// NO idea how to send it as reponse...
});
}
In console there is response with type string, starting with something like this:
%PDF-1.4
%����
3 0 obj
<
</Type /XObject /Subtype /Image /Width 1171 /Height 1676 /ColorSpace /DeviceRGB /BitsPerComponent 8 /Decode [0 1 0 1 0 1] /Interpolate false /Filter /FlateDecode /DecodeParms<
</Predictor 12 /Colors 3 /Columns 1171 >>
/Length 61782 >>
stream
X���o�]�}'�;!Yl"�ɠh����x�H&�r�h�@(�3[ҋHK"�r+)K�q{kYL���fl���H�)��@�By�v�Ԭ\Z��3�-�5�Զ*PEJ���EU�����G�Ϲ�v���t��S��n���s�sn��>�y���1y��y��r'��Nrȝ��;�
wݓ�Ν;�m��b�X,��b�X,s�D �MO?�܊,6@rK&''w����b���266�H�%��_~��r�C���X,�e�K��������U��۲e���%+�������|���*��?pr �@�$7��In���r'��Nrȝ�0���o���|עʑ#Gn�������u�s��Z���ɓqe��|U >��9z�%�ٳw
....