I just started to study aws lambda & gateway and now I'm trying to make a simple API with aws Lambda.
This is my lambda function.
'use strict'
console.log('Loading event');
exports.handler = function(event, context, callback) {
var name = (event.name === undefined? 'No-Name' : event.name);
callback(null, {"Your-name" : name}); // SUCCESS with message
};
This is my mapping template.(Content-Type : application/json)
{"name" : "$input.params('name')"}
I want to change the value of name, so I tried,
var xhr = new XMLHttpRequest();
xhr.open('GET', 'my api url...');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
console.log(xhr.response);
}
};
xhr.setRequestHeader("Content-Type", "application/json");
xhr.responseType = 'json';
var name = "JACK";
xhr.send(name);
It doesn't work. I want something like {"Your-name" : "JACK"} but it only returns {"Your-name" : "No-Name"}. How can I solve this problem?
Did you try:
var json = JSON.stringify({ name: "JACK" });
xhr.send(json);
?
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments