Reputation: 5637
I have an OpenWhisk action that returns a response object, because I want to be able to control the headers and HTTP status code. My action returns something like this:
return {
statusCode: 200,
headers: { 'Content-Type': 'application/json' },
body: { x: 1 }
};
I deploy the action in a package from the command-line with:
wsk action update myproj/myaction --kind nodejs:6 myaction.zip --web true
And expose it as API on IBM Cloud Functions with:
wsk api create /myproj /myaction get myproj/myaction
But when I visit the API call with curl
, I get the whole response object, not just the data:
curl '.../myproj/myaction'
{
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": { x: 1 }
}
I was expecting to get just { x: 1 }
.
What do I need to do to fix this?
Upvotes: 1
Views: 239
Reputation: 4339
The default API Gateway service behaviour expects body data to be returned from the action, not the full HTTP response parameters.
Change the return statement to the following to resolve this issue.
return {
x: 1
};
Controlling the full HTTP response using the returned action parameters needs the --response-type http
flag setting on the web action.
$ wsk api create /myproj /myaction get myproj/myaction --response-type http
Upvotes: 2