Module Context
Context example :
Context example
{
"snowflake": "xxxx", // request unique id
"request": { // original request unchanged by otoroshi
"method": "GET",
"path": "/foo",
"headers": {
"user-agent":"foo"
}
},
"raw_request": { // only defined in the on_request phase
"method": "GET",
"path": "/foo",
"headers": {
"user-agent":"foo"
}
},
"otoroshi_request": { // only defined in the on_request phase
"method": "GET",
"path": "/foo",
"headers": {
"user-agent":"foo"
}
},
"body": [12, 23, 34], // request body as a byte array, not defined in the on_validate phase
"apikey": { // the request apikey if provided
"clientId": "foo",
"clientName": "foo",
"metadata": [],
"tags": [],
},
"user": { // the request user if provided
"name": "foo",
"email": "foo@foo.com",
"profile": {}, // idp dependant user profile
"metadata":[],
"tags": [],
}
"raw_response": { // only defined in the on_response and on_error phase
"status": 200,
"headers": {
"content-type": "text/html"
},
"body": [12, 23, 34]
},
"otoroshi_response": { // only defined in the on_response and on_error phase
"status": 200,
"headers": {
"content-type": "text/html"
},
"body": [12, 23, 34]
},
"cause_id": "xxx", // only defined in the on_error phase
"call_attempts": 3, // only defined in the on_error phase
"message": "error", // only defined in the on_error phase
}
How to use context
You need to use context like this :
Context use example
function(ctx) {
// Original request use :
// ctx.request
// ApiKeys information (if provided):
// ctx.apikey
// User information (if provided):
// ctx.user
return ...
}