Handle Submit (API CleanURI)
Fri Mar 15 2024 07:07:08 GMT+0000 (Coordinated Universal Time)
Saved by
@fazmi322
const handleSubmit = async () => {
const uri = encodeURIComponent(inputValue.toString());
const url = "https://cleanuri.com";
const shortenAPI = `${url}/api/v1/shorten`;
if(uri!==""){
try {
const res = await fetch(shortenAPI, {
method: "POST",
body: `url=${uri}`,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
});
if (!res.ok) {
throw new Error(`HTTP error! status: ${res.status}`);
}
const dataJSON = await res.json();
setData([...data, { input: inputValue, result: dataJSON.result_url }]);
setInputValue("");
} catch (error) {
console.error("Fetch error:", error);
}
}
else{
setAlertInput(!alertInput)
}
};
content_copyCOPY
Comments