May 23, 2024, 8:13 p.m. | antonmak1

DEV Community dev.to

Perhaps it will help someone. You can use the cample-html package to load HTML from the server. It works on fetch, so it can help you avoid writing a bunch of code:



<div>
<template
data-cample
data-src="/api/text"
data-method="get"
>
</template>
</div>
<script src="https://unpkg.com/cample-html"></script>


Or, if you need to work through javascript, you can use the createTemplate method:



<script src="https://unpkg.com/cample-html"></script>
<script>
const templateFn = CampleHTML.createTemplate(
`<template data-cample data-src="/api/test" data-method="get"></template>`
);

const wrapper = document.getElementById("wrapper");

const elementObj = templateFn({
credentials: "same-origin",
get: (prop, …

api beginners code data fetch html javascript package programming server template text through webdev will work writing

AI Focused Biochemistry Postdoctoral Fellow

@ Lawrence Berkeley National Lab | Berkeley, CA

Senior Data Engineer

@ Displate | Warsaw

Associate Director, IT Business Partner, Cell Therapy Analytical Development

@ Bristol Myers Squibb | Warren - NJ

Solutions Architect

@ Lloyds Banking Group | London 125 London Wall

Senior Lead Cloud Engineer

@ S&P Global | IN - HYDERABAD ORION

Software Engineer

@ Applied Materials | Bengaluru,IND