lambda-proxy icon indicating copy to clipboard operation
lambda-proxy copied to clipboard

WIP - Version 6

Open vincentsarago opened this issue 5 years ago • 1 comments

This PR is a first sketch for next lambda-proxy version (6)

Changes:

  • New way to create and handle response
  • New way to hander exception
  • FastAPI/Starlette style API
  • JSON is the new default response model

Version 5 (Master)

@app.get("/ping", cors=True)		
def health():		
    return ("OK", "text/plain", "I'm healthy")

Version 6 (This PR)

from lambda_proxy.responses import PlainTextResponse

@app.get("/ping", cors=True, response_class=PlainTextResponse)		
def health():		
    return "I'm way more healthy"
Bonus - Custom headers

inspired by https://fastapi.tiangolo.com/advanced/response-headers/#use-a-response-parameter

from lambda_proxy.responses import Response, PlainTextResponse

@app.get("/ping", cors=True, response_class=PlainTextResponse)		
def health(resp: Response):
    resp.headers["X-Custom"] = "This is cool"
    return "I'm way more healthy"

cc @kylebarron

vincentsarago avatar May 21 '20 17:05 vincentsarago

To Do

  • [ ] update tests
  • [ ] update docs
  • [ ] update demo

vincentsarago avatar May 21 '20 17:05 vincentsarago