@@ -28,37 +28,37 @@ class CORSConfig(object):
2828
2929 Simple cors example using the default permissive cors, not this should only be used during early prototyping
3030
31- >>> from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver
32- >>>
33- >>> app = ApiGatewayResolver()
34- >>>
35- >>> @app.get("/my/path", cors=True)
36- >>> def with_cors():
37- >>> return {"message": "Foo"}
31+ from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver
32+
33+ app = ApiGatewayResolver()
34+
35+ @app.get("/my/path", cors=True)
36+ def with_cors():
37+ return {"message": "Foo"}
3838
3939 Using a custom CORSConfig where `with_cors` used the custom provided CORSConfig and `without_cors`
4040 do not include any cors headers.
4141
42- >>> from aws_lambda_powertools.event_handler.api_gateway import (
43- >>> ApiGatewayResolver, CORSConfig
44- >>> )
45- >>>
46- >>> cors_config = CORSConfig(
47- >>> allow_origin="https://wwww.example.com/",
48- >>> expose_headers=["x-exposed-response-header"],
49- >>> allow_headers=["x-custom-request-header"],
50- >>> max_age=100,
51- >>> allow_credentials=True,
52- >>> )
53- >>> app = ApiGatewayResolver(cors=cors_config)
54- >>>
55- >>> @app.get("/my/path", cors=True)
56- >>> def with_cors():
57- >>> return {"message": "Foo"}
58- >>>
59- >>> @app.get("/another-one")
60- >>> def without_cors():
61- >>> return {"message": "Foo"}
42+ from aws_lambda_powertools.event_handler.api_gateway import (
43+ ApiGatewayResolver, CORSConfig
44+ )
45+
46+ cors_config = CORSConfig(
47+ allow_origin="https://wwww.example.com/",
48+ expose_headers=["x-exposed-response-header"],
49+ allow_headers=["x-custom-request-header"],
50+ max_age=100,
51+ allow_credentials=True,
52+ )
53+ app = ApiGatewayResolver(cors=cors_config)
54+
55+ @app.get("/my/path", cors=True)
56+ def with_cors():
57+ return {"message": "Foo"}
58+
59+ @app.get("/another-one")
60+ def without_cors():
61+ return {"message": "Foo"}
6262 """
6363
6464 _REQUIRED_HEADERS = ["Authorization" , "Content-Type" , "X-Amz-Date" , "X-Api-Key" , "X-Amz-Security-Token" ]
@@ -207,27 +207,26 @@ class ApiGatewayResolver:
207207 --------
208208 Simple example with a custom lambda handler using the Tracer capture_lambda_handler decorator
209209
210- >>> from aws_lambda_powertools import Tracer
211- >>> from aws_lambda_powertools.event_handler.api_gateway import (
212- >>> ApiGatewayResolver
213- >>> )
214- >>>
215- >>> tracer = Tracer()
216- >>> app = ApiGatewayResolver()
217- >>>
218- >>> @app.get("/get-call")
219- >>> def simple_get():
220- >>> return {"message": "Foo"}
221- >>>
222- >>> @app.post("/post-call")
223- >>> def simple_post():
224- >>> post_data: dict = app.current_event.json_body
225- >>> return {"message": post_data["value"]}
226- >>>
227- >>> @tracer.capture_lambda_handler
228- >>> def lambda_handler(event, context):
229- >>> return app.resolve(event, context)
210+ ```python
211+ from aws_lambda_powertools import Tracer
212+ from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver
213+
214+ tracer = Tracer()
215+ app = ApiGatewayResolver()
216+
217+ @app.get("/get-call")
218+ def simple_get():
219+ return {"message": "Foo"}
230220
221+ @app.post("/post-call")
222+ def simple_post():
223+ post_data: dict = app.current_event.json_body
224+ return {"message": post_data["value"]}
225+
226+ @tracer.capture_lambda_handler
227+ def lambda_handler(event, context):
228+ return app.resolve(event, context)
229+ ```
231230 """
232231
233232 current_event : BaseProxyEvent
@@ -248,23 +247,133 @@ def __init__(self, proxy_type: Enum = ProxyEventType.APIGatewayProxyEvent, cors:
248247 self ._cors_methods : Set [str ] = {"OPTIONS" }
249248
250249 def get (self , rule : str , cors : bool = True , compress : bool = False , cache_control : str = None ):
251- """Get route decorator with GET `method`"""
250+ """Get route decorator with GET `method`
251+
252+ Examples
253+ --------
254+ Simple example with a custom lambda handler using the Tracer capture_lambda_handler decorator
255+
256+ ```python
257+ from aws_lambda_powertools import Tracer
258+ from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver
259+ >>>
260+ tracer = Tracer()
261+ app = ApiGatewayResolver()
262+
263+ @app.get("/get-call")
264+ def simple_get():
265+ return {"message": "Foo"}
266+
267+ @tracer.capture_lambda_handler
268+ def lambda_handler(event, context):
269+ return app.resolve(event, context)
270+ ```
271+ """
252272 return self .route (rule , "GET" , cors , compress , cache_control )
253273
254274 def post (self , rule : str , cors : bool = True , compress : bool = False , cache_control : str = None ):
255- """Post route decorator with POST `method`"""
275+ """Post route decorator with POST `method`
276+
277+ Examples
278+ --------
279+ Simple example with a custom lambda handler using the Tracer capture_lambda_handler decorator
280+
281+ ```python
282+ from aws_lambda_powertools import Tracer
283+ from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver
284+
285+ tracer = Tracer()
286+ app = ApiGatewayResolver()
287+
288+ @app.post("/post-call")
289+ def simple_post():
290+ post_data: dict = app.current_event.json_body
291+ return {"message": post_data["value"]}
292+
293+ @tracer.capture_lambda_handler
294+ def lambda_handler(event, context):
295+ return app.resolve(event, context)
296+ ```
297+ """
256298 return self .route (rule , "POST" , cors , compress , cache_control )
257299
258300 def put (self , rule : str , cors : bool = True , compress : bool = False , cache_control : str = None ):
259- """Put route decorator with PUT `method`"""
301+ """Put route decorator with PUT `method`
302+
303+ Examples
304+ --------
305+ Simple example with a custom lambda handler using the Tracer capture_lambda_handler decorator
306+
307+ ```python
308+ from aws_lambda_powertools import Tracer
309+ from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver
310+
311+ tracer = Tracer()
312+ app = ApiGatewayResolver()
313+
314+ @app.put("/put-call")
315+ def simple_post():
316+ put_data: dict = app.current_event.json_body
317+ return {"message": put_data["value"]}
318+
319+ @tracer.capture_lambda_handler
320+ def lambda_handler(event, context):
321+ return app.resolve(event, context)
322+ ```
323+ """
260324 return self .route (rule , "PUT" , cors , compress , cache_control )
261325
262326 def delete (self , rule : str , cors : bool = True , compress : bool = False , cache_control : str = None ):
263- """Delete route decorator with DELETE `method`"""
327+ """Delete route decorator with DELETE `method`
328+
329+ Examples
330+ --------
331+ Simple example with a custom lambda handler using the Tracer capture_lambda_handler decorator
332+
333+ ```python
334+ from aws_lambda_powertools import Tracer
335+ from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver
336+
337+ tracer = Tracer()
338+ app = ApiGatewayResolver()
339+
340+ @app.delete("/delete-call")
341+ def simple_delete():
342+ return {"message": "deleted"}
343+
344+ @tracer.capture_lambda_handler
345+ def lambda_handler(event, context):
346+ return app.resolve(event, context)
347+ ```
348+ """
264349 return self .route (rule , "DELETE" , cors , compress , cache_control )
265350
266351 def patch (self , rule : str , cors : bool = True , compress : bool = False , cache_control : str = None ):
267- """Patch route decorator with PATCH `method`"""
352+ """Patch route decorator with PATCH `method`
353+
354+ Examples
355+ --------
356+ Simple example with a custom lambda handler using the Tracer capture_lambda_handler decorator
357+
358+ ```python
359+ from aws_lambda_powertools import Tracer
360+ from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver
361+
362+ tracer = Tracer()
363+ app = ApiGatewayResolver()
364+
365+ @app.patch("/patch-call")
366+ def simple_patch():
367+ patch_data: dict = app.current_event.json_body
368+ patch_data["value"] = patched
369+
370+ return {"message": patch_data}
371+
372+ @tracer.capture_lambda_handler
373+ def lambda_handler(event, context):
374+ return app.resolve(event, context)
375+ ```
376+ """
268377 return self .route (rule , "PATCH" , cors , compress , cache_control )
269378
270379 def route (self , rule : str , method : str , cors : bool = True , compress : bool = False , cache_control : str = None ):
0 commit comments