mirror of
https://github.com/serverless/serverless.git
synced 2025-12-08 19:46:03 +00:00
Make Response API Gateway Compliant
This commit is contained in:
parent
ca1eee3e05
commit
a53893e33b
@ -56,10 +56,11 @@ functions:
|
||||
# The following are a few example events you can configure
|
||||
# NOTE: Please make sure to change your handler code to work with those events
|
||||
# Check the event documentation for details
|
||||
# events:
|
||||
# - http:
|
||||
# path: users/create
|
||||
# method: get
|
||||
events:
|
||||
- http:
|
||||
path: hello
|
||||
method: get
|
||||
cors: true
|
||||
# - s3: ${env:BUCKET}
|
||||
# - schedule: rate(10 minutes)
|
||||
# - sns: greeter-topic
|
||||
|
||||
@ -7,6 +7,6 @@ import groovy.transform.builder.Builder
|
||||
@CompileStatic
|
||||
class ApiGatewayResponse {
|
||||
int statusCode
|
||||
Response body
|
||||
String body
|
||||
Map<String, String> headers
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ class Handler implements RequestHandler<Map<String, Object>, ApiGatewayResponse>
|
||||
.build()
|
||||
return ApiGatewayResponse.builder()
|
||||
.statusCode(200)
|
||||
.body(responseBody)
|
||||
.body(responseBody.toJson())
|
||||
.headers(['X-Powered-By': 'AWS Lambda & serverless'])
|
||||
.build()
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.serverless
|
||||
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.transform.builder.Builder
|
||||
|
||||
@ -8,4 +9,8 @@ import groovy.transform.builder.Builder
|
||||
class Response {
|
||||
Object message
|
||||
Map<String, Object> input
|
||||
|
||||
String toJson() {
|
||||
return JsonOutput.prettyPrint(JsonOutput.toJson(this))
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user