Skip to content

Instantly share code, notes, and snippets.

@Sonsuz
Last active November 13, 2022 20:50
Show Gist options
  • Save Sonsuz/f34c2af7ea73967c983b2b760f4b738b to your computer and use it in GitHub Desktop.
Save Sonsuz/f34c2af7ea73967c983b2b760f4b738b to your computer and use it in GitHub Desktop.
updated index for web app
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<title>Hello World</title>
<style>
body {
background-color: #232F3E;
}
label, button {
color: #FF9900;
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
margin-left: 40px;
}
input {
color: #232F3E;
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
margin-left: 20px;
}
</style>
<script>
var callAPI = (fname, lname)=>{
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({"firstname":fname,"lastname":lname});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("api-key", requestOptions)
.then(response => response.text())
.then(result => alert(JSON.parse(result).message))
.catch(error => console.log('error', error));
}
</script>
</head>
<body>
<form>
<label>First Name :</label>
<input type="text" id="fName">
<label>Last Name :</label>
<input type="text" id="lName">
<button type="button" onclick="callAPI(document.getElementById('fName').value, document.getElementById('lName').value)">Call API</button>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment