-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-tester.js
46 lines (41 loc) · 1.44 KB
/
api-tester.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const AWS = require('aws-sdk');
const dynamodb = AWS.DynamoDB(region:'us-west-2', apiVersion:'2012-08-10');
const table = 'Ingredients';
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
const xhr = new XMLHttpRequest(),
method = "POST",
// url = "https://00q70ys3xc.execute-api.us-west-2.amazonaws.com/dev/grocerylist/''";
url = "https://00q70ys3xc.execute-api.us-west-2.amazonaws.com/dev/ingredients"
xhr.open(method, url, true);
xhr.onreadystatechange = function () {
// In local files, status is 0 upon success in Mozilla Firefox
if(xhr.readyState === 4) { // 0 unsent, 1 opened, 2 headers received, 3 loading, 4 done.
var status = xhr.status;
if (status === 0 || (status >= 200 && status < 400)) {
// The request has been completed successfully
console.log(`status: ${status}, response: ${xhr.responseText}`);
}
else
{
console.log(`status: ${status}, response: ${xhr.responseText}`);
// Oh no! There has been an error with the request!
}
}
};
let ingredient = {
name:"Lamb",
type:"Meat",
color:"red",
}
xhr.send(JSON.stringify(ingredient));
/*
let XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
let xhr = new XMLHttpRequest();
xhr.open('GET',
'https://00q70ys3xc.execute-api.us-west-2.amazonaws.com/dev/grocerylist/all');
xhr.onreadystatechange = function(event){
console.log(event);
}
xhr.setRequestHeader('Content-type', 'application/json');
xhr.send();
*/