You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/event_handler/api_gateway.md
+38-1
Original file line number
Diff line number
Diff line change
@@ -408,6 +408,43 @@ Key | Value | Note
408
408
409
409
### Fine grained responses
410
410
411
+
You can use the `Response` class to have full control over the response, for example you might want to add additional headers or set a custom Content-type.
412
+
413
+
=== "app.py"
414
+
415
+
```python hl_lines="10-14"
416
+
from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver, Response
417
+
418
+
app = ApiGatewayResolver()
419
+
420
+
@app.get("/hello")
421
+
def get_hello_you():
422
+
payload = json.dumps({"message": "I'm a teapot"})
423
+
custom_headers = {"X-Custom": "X-Value"}
424
+
425
+
return Response(status_code=418,
426
+
content_type="application/json",
427
+
body=payload,
428
+
headers=custom_headers
429
+
)
430
+
431
+
def lambda_handler(event, context):
432
+
return app.resolve(event, context)
433
+
```
434
+
435
+
=== "response.json"
436
+
437
+
```json
438
+
{
439
+
"body": "{\"message\":\"I\'m a teapot\"}",
440
+
"headers": {
441
+
"Content-Type": "application/json",
442
+
"X-Custom": "X-Value"
443
+
},
444
+
"isBase64Encoded": false,
445
+
"statusCode": 418
446
+
}
447
+
411
448
### Compress
412
449
413
450
You can compress with gzip and base64 encode your responses via `compress` parameter.
@@ -417,7 +454,7 @@ You can compress with gzip and base64 encode your responses via `compress` param
417
454
=== "app.py"
418
455
419
456
```python hl_lines="5 7"
420
-
from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver, Response
457
+
from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver
0 commit comments