Documentation

Read and Paste the code snippets in the respective file

<HTML />

Put correct values in name attributes of your "email" and "name" inputs attribute as mentioned in your HTML file(s)

Name input → type="text" name="client_name"
                
Email input → type="email" name="client_email"

<JavaScript />

Add Script to your HTML file or Seperate .js file

                    copy
                
    <script type="text/javascript">
        let baseUrl = "http://127.0.0.1:8000";
        let targetUrl = new URL("/dashboard", baseUrl); 
        const submit = document.querySelector('#submit') 
        submit.addEventListener('click',(e)=>{
        e.preventDefault();
        fetch(`http://127.0.0.1:8000/api/request_newsletter`,{
            method:'POST',
            headers:{
                'Content-Type':'Application/json',
            },
        })
        .then(res=>res.json())
        .then(json=>{
            window.location.href = targetUrl.href;
        })
        });    
    </script>