Skip to content

Instantly share code, notes, and snippets.

@jonathanlurie
Last active February 22, 2018 17:08
Show Gist options
  • Save jonathanlurie/7a6087777b02f98b78c04a157fe6084d to your computer and use it in GitHub Desktop.
Save jonathanlurie/7a6087777b02f98b78c04a157fe6084d to your computer and use it in GitHub Desktop.
Posting to Webtask
<html>
<head>
<title>test</title>
</head>
<body>
<div id="output"></div>
<script>
var output = document.getElementById("output")
var baseUrl = 'https://wt-3d8e69c28886f9c9f7ed6ba6797d805b-0.run.webtask.io/simpletest';
var route = "/ping";
var url = baseUrl + route;
var dataToSend = {
arg1: "A simple string",
arg2: 444
}
fetch(url,
{
method: "POST",
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify( dataToSend )
})
.then(function(res){
status = res.status;
if( status > 200 ){
throw "Server error, status " + status;
return;
}
return res.json();
})
.then(function(data){
output.innerHTML = JSON.stringify( data );
console.log( data );
})
.catch(function(e){
output.innerHTML = JSON.stringify( {error: 1, message: e} );
console.log( e );
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment