Skip to content

Instantly share code, notes, and snippets.

@rcdelacruz
Last active January 23, 2018 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcdelacruz/90f82ef5696ffc3eac8db7de952dba74 to your computer and use it in GitHub Desktop.
Save rcdelacruz/90f82ef5696ffc3eac8db7de952dba74 to your computer and use it in GitHub Desktop.
demo - hello world
function renderTemp(data) {
var el = document.getElementById('temperature');
el.innerHTML = data.temperature + " °C";
}
// replace with the endpoint created in your deployment.
var endpoint = 'http://localhost:3000/weather';
fetch(endpoint, { mode: 'cors' })
.then(function (resp) {
return resp.json();
})
.then(renderTemp);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>What is the temperature?</title>
<style>
h1,
h2 {
text-align: center;
font-family: sans-serif;
color: #333;
}
</style>
</head>
<body>
<h1>What is the temperature?</h1>
<h2 id='temperature'>Checking...</h2>
<script src="app.js" charset="utf-8"></script>
</body>
</html>
module.exports.getWeather = (event, context, callback) => {
const data = { temperature: 19.2 };
const response = {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify(data)
};
callback(null, response);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment