Closed QAnders closed 4 years ago
Code to reproduce
This is an object, I need a full code to reproduce the issue.
The API I call is a private API requiring AUTH and I haven't found any public HATEOS (hal+json) API's to test against. The code would be just a regular GET, eg:
const options = {
uri: 'https://some.hateos.api/,
headers: {
Accept: 'application/hal+json'
}
}
try {
const response = await https.get(options.uri, { headers: options.headers });
return response.body;
} catch (error) {
console.log('getBBCSearchResult error:', error);
throw new Error('getBBCSearchResult error: ' + error);
}
In the example above you're missing the responseType
option.
Sorry, forgot it in the sample I wrote up but it's in the original post...
Strangely, that didn't work but now adding it as:
const response = await https.get(options.uri, { headers: options.headers, responseType: 'json' });
does work...
I'll leave it like that and thanks for getting back to me!
Describe the bug
Calling an API that requires the use of
application/hal+json
as Accepted content-type is not being returned as JSON but as String.responseType: 'json'
does not have any affect.Actual behavior
Returns
String
Expected behavior
Return
JSON
Code to reproduce
Checklist