#How can i return html in a API route
1 messages · Page 1 of 1 (latest)
To return HTML in an API route, you can create a response with the Content-Type header set to "text/html". Here's an example:
// Example: src/pages/api/some-html.js
export async function get(params, request) {
const htmlContent = `
<!DOCTYPE html>
<html>
<head>
<title>Example HTML</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
`;
return new Response(htmlContent, {
status: 200,
headers: {
"Content-Type": "text/html",
},
});
}