Skip to content

Commit f34a6f3

Browse files
authored
Merge pull request #21 from thaunghtike-share/main
convert to fast api
2 parents cfb3919 + 697885f commit f34a6f3

File tree

6 files changed

+18
-8146
lines changed

6 files changed

+18
-8146
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var/
1616
*.egg-info/
1717
.installed.cfg
1818
*.egg
19+
.coverage
1920

2021
# Serverless directories
2122
.serverless

app.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
11
import os
22

3-
from flask import Flask, render_template
4-
3+
from fastapi import FastAPI, Request
4+
from fastapi.templating import Jinja2Templates
5+
from fastapi.responses import HTMLResponse
6+
from mangum import Mangum
57
from pynamodb.models import Model
68
from pynamodb.attributes import UnicodeAttribute
79

8-
app = Flask(__name__)
910

11+
app = FastAPI()
12+
templates = Jinja2Templates(directory="templates")
1013
class OneTable(Model):
1114
'''
1215
DynamoDB works best with a single table. This table. Use this table to model
1316
other data requests.
1417
'''
1518
class Meta:
16-
table_name = os.environ['DYNAMODB_TABLE_NAME']
19+
table_name = 'DYNAMODB_TABLE_NAME'
1720

1821
pk = UnicodeAttribute(hash_key=True)
1922
sk = UnicodeAttribute(range_key=True)
2023

21-
@app.route("/")
22-
def cats():
23-
return render_template('index.html')
24+
@app.get("/", response_class=HTMLResponse)
25+
def cats(request: Request):
26+
return templates.TemplateResponse("index.html", {"request":request})
2427

25-
@app.route("/dogs/<id>")
28+
@app.get("/dogs/{id}")
2629
def dog(id):
2730
return "Dog"
2831

29-
@app.route("/health")
32+
@app.get("/health")
3033
def health():
31-
return { "status": "Success" }
34+
return {"status": "Success"}
35+
36+
handler = Mangum(app)

0 commit comments

Comments
 (0)