I have used the shrtcode api and I dont know how to store its data.
var requestOptions = {
method: 'GET',
redirect: 'follow'
};
fetch("https://api.shrtco.de/v2/shorten?url=www.google.com", requestOptions)//api
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
}
Response
ok true
result
code "fQdPc"
short_link "shrtco.de/fQdPc"
full_short_link "https://shrtco.de/fQdPc"
short_link2 "9qr.de/fQdPc"
full_short_link2 "https://9qr.de/fQdPc"
short_link3 "shiny.link/fQdPc"
full_short_link3 "https://shiny.link/fQdPc"
share_link "shrtco.de/share/fQdPc"
full_share_link "https://shrtco.de/share/fQdPc"
original_link "http://www.google.com"
How can I print or store the value of "full_short_link "?
CodePudding user response:
Like this?
const doStuff = async () => {
try {
const res = await fetch('https://api.shrtco.de/v2/shorten?url=www.google.com');
const json = await res.json();
console.log('full_short_link', json.result.full_short_link);
} catch (err) {
console.error(err);
}
};
doStuff();