Skip to content

Instantly share code, notes, and snippets.

@christopheranderson
Created January 9, 2018 23:27
Show Gist options
  • Save christopheranderson/3fbb30397f25ff4bc41da14b1884b66f to your computer and use it in GitHub Desktop.
Save christopheranderson/3fbb30397f25ff4bc41da14b1884b66f to your computer and use it in GitHub Desktop.
Example context object for Azure Functions
{
"invocationId": "a3ea24b8-d262-41d0-a57b-f6a207ade9c2",
"executionContext": {
"invocationId": "a3ea24b8-d262-41d0-a57b-f6a207ade9c2",
"functionName": "hello",
"functionDirectory": "C:\\workspace\\temp\\contextjs\\hello"
},
"log": "[FUNCTION]",
"bindingData": {
"invocationId": "a3ea24b8-d262-41d0-a57b-f6a207ade9c2",
"query": {},
"headers": {
"Connection": "Keep-Alive",
"Accept": "text/html, application/xhtml+xml, image/jxr, */*",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en-US",
"Host": "localhost:7071",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063"
},
"sys": {
"MethodName": "hello",
"UtcNow": "2018-01-09T23:11:03.2262784Z",
"RandGuid": "4d79dacd-9e06-4808-8eb9-efa75e9dd308"
}
},
"done": "[FUNCTION]",
"bindings": {
"req": {
"method": "GET",
"url": "/api/hello",
"originalUrl": "/api/hello",
"headers": {
"connection": "Keep-Alive",
"accept": "text/html, application/xhtml+xml, image/jxr, */*",
"accept-encoding": "gzip, deflate",
"accept-language": "en-US",
"host": "localhost:7071",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063"
},
"query": {},
"params": {}
}
},
"req": {
"method": "GET",
"url": "/api/hello",
"originalUrl": "/api/hello",
"headers": {
"connection": "Keep-Alive",
"accept": "text/html, application/xhtml+xml, image/jxr, */*",
"accept-encoding": "gzip, deflate",
"accept-language": "en-US",
"host": "localhost:7071",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063"
},
"query": {},
"params": {}
},
"res": {
"headers": {},
"send": "[FUNCTION]",
"set": "[FUNCTION]",
"header": "[FUNCTION]",
"get": "[FUNCTION]",
"_done": "[FUNCTION]"
}
}
// This generates the above output
module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
let ctx = JSON.stringify(context, (k, v) => {
if (typeof v === "function") {
return "[FUNCTION]";
}
return v;
}, ' ');
context.log(ctx);
context.res = {
body: ctx
}
context.done();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment