Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

responseParameters support #12

Closed
spardo opened this issue Mar 10, 2016 · 15 comments
Closed

responseParameters support #12

spardo opened this issue Mar 10, 2016 · 15 comments

Comments

@spardo
Copy link

spardo commented Mar 10, 2016

Would like support for responseParameters.

Not sure if the example below is valid but would like to dynamically load responses to the header, such as location for a newly created item.

"responses": {
   "default": {
      "statusCode": "201",
      "responseParameters": {
         "method.response.header.Location": "integration.response.body.location"
      },
      "responseModels": {},
      "responseTemplates": {
         "application/json": "$input.path('$.body')"
      }
   }
}
@martinmicunda
Copy link
Contributor

I am currently working on error API Gateway and lambda error handling and here is my use case:

"responses": {
   "default": {
      "statusCode": "200",
      "responseParameters": {},
      "responseModels": {},
      "responseTemplates": {
          "application/json": ""
      }
   },
   ".*\"statusCode\":404.*": {
      "statusCode": "404",
      "responseParameters": {},
      "responseModels": {},
      "responseTemplates": {
        "application/json": "#set($inputRoot = $input.path('$.errorMessage'))\n$inputRoot"
      }
   }
}

handler.js

context.fail(JSON.stringify({"statusCode":404,"error":"Not Found"}));

The above example works on AWS. Not sure if this on your roadmap but it would be nice if offline plugin could match regular expression and return 404 statusCode with errorMessage (currently is returning 200). This is nice article about API Gateway error handling.

@dherault
Copy link
Owner

@spardo spardo Using (request and response) parameters is hard because it really has to do with integrations, but I'll try something.

@martinmicunda You can teak you template to make it work with Offline:

   "404": {
      "statusCode": "404",
      "selectionPattern": ".*\"statusCode\":404.*",
      "responseParameters": {},
      "responseModels": {},
      "responseTemplates": {
        "application/json": "#set($inputRoot = $input.path('$.errorMessage'))\n$inputRoot"
      }
   }

But I'll commit something to make it work with your code soon.

@dherault
Copy link
Owner

@martinmicunda Solved in v1.2.2.

@spardo It seems like a long road, but request and response parameters are on their way 😅
EDIT: I'll finally wait for Serverless 0.5 before I work on that.

@martinmicunda
Copy link
Contributor

I am starting to have same request like @spardo :) I try to set up response content-type to json (offline currently return conte-type as text) so it would be nice to have this feature in the offline plugin :)

  "responseParameters": {
    "method.response.header.Content-Type": "'application/json; charset=UTF-8'"
  }

@dherault
Copy link
Owner

Content-type returned as text is a bug! I'll fix it!
I've been thinking about request/responseParameters, it's possible, but will take some time.

@martinmicunda
Copy link
Contributor

thanks...

@dherault
Copy link
Owner

I don't see the response content-type set as text, in which case do you have this ?

@dherault
Copy link
Owner

Anyway, I worked a fix, v1.2.6, please review it, thanks.

@martinmicunda
Copy link
Contributor

sorry .. The content-type doesn't seem to be set at all... I am using Postman for testing and I have test for response content-type. Shouldn't the offline plugin send content-type="application/json; charset=UTF-8" or at least to be able somehow to configure respond..

cache-control:no-cache
Connection:keep-alive
content-length:139
Date:Tue, 15 Mar 2016 15:42:17 GMT
vary:origin,accept-encoding

@dherault
Copy link
Owner

With v1.2.6 ?

@martinmicunda
Copy link
Contributor

just pulled latest version and it works ... thanks ;)

@dherault
Copy link
Owner

Sweet! I'll start working on request/responseParameters right away. Won't be before friday I think.

EDIT: @spardo @martinmicunda Only responseParameters for starters, because for requestParameters I need to hijack Hapijs's request, I'll do that later.

@dherault
Copy link
Owner

@spardo @martinmicunda So it seems that only header modification is supported by APIG's responseParameters when it comes to lambda integrations.

1.3.0 is on it's way, will support
"method.response.header.xxx": "integration.response.body"
"method.response.header.xxx": "integration.response.body.__JSONpath__"
"method.response.header.xxx": "integration.response.header.yyy"
"method.response.header.xxx": "__customHeader__"

Also, the current doc is ugly and confusing so I'll work on that.

@dherault
Copy link
Owner

@spardo @martinmicunda Done. run npm update to download the new v1.3.0.
See the new docs for usage. Happy coding!

@spardo
Copy link
Author

spardo commented Apr 5, 2016

Thank you very much and sorry for going dark, I was not receiving any email notifications. Can't wait to test it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants