escape and unescape html special characters
// output appears here
curl -sX POST 'https://api.whittly.dev/v1/html/encode' \
-H 'Authorization: Bearer $WHITTLY_API_KEY' \
-H 'Content-Type: application/json' \
-d '{"input":"<div class=\"hello\">World & Co</div>"}'
const res = await fetch('https://api.whittly.dev/v1/html/encode', {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + apiKey,
'Content-Type': 'application/json',
},
body: JSON.stringify({ input: "<div class=\"hello\">World & Co</div>" }),
});
const data = await res.json();
const { data } = await axios.post(
'https://api.whittly.dev/v1/html/encode',
{ input: "<div class=\"hello\">World & Co</div>" },
{ headers: { Authorization: 'Bearer ' + apiKey } }
);
HTML entities are escape sequences for characters that have special meaning in HTML (&, <, >, ", '). Encoding user-provided content before inserting it into HTML prevents Cross-Site Scripting (XSS) attacks where malicious scripts are injected into web pages.