After transitioning a one-time fetch request code snippet to my API, I encountered the following:
let response = await fetch(visitURL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + userJWT
},
body: JSON.stringify(endingVisit)
});
if (response.ok) {
let {visitId, createdAt} = await response.json();
const viewVisitDto = new ViewVisitDto(`${visitId}${createdAt}${visitorId}${doctorId}${oldPatientId}`);
return viewVisitDto;
} else {
throw new Error("deactivated!")
}
I made some progress with this:
axios.post(visitURL, {
headers,
body: JSON.stringify(visit)
}).then((response) => {
console.log(response);
}).catch((error) => {
console.log(error);
})
However, I am unable to extract the visitId
and createdAt
from the response. I am unable to use response.ok
or response.json()
. I need to find a way to retrieve the visitId
and createdAt
that are supposed to be included in the response.
I also attempted to use the node-fetch
library, but despite Visual Studio Code accepting it, TypeScript does not recognize it even after installing @types/node-fetch
and creating a type definition file for it.