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: README.qmd
+41Lines changed: 41 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,47 @@ format: gfm
9
9
10
10
This project is still under development.
11
11
12
+
### Architecture
13
+
14
+
This application uses a Post-Redirect-Get (PRG) pattern. The user submits a form, which sends a POST request to a FastAPI endpoint on the server. The database is updated, and the user is redirected to a GET endpoint, which fetches the updated data and re-renders the Jinja2 page template with the new data.
15
+
16
+
```{python}
17
+
#| echo: false
18
+
#| include: false
19
+
from graphviz import Digraph
20
+
21
+
dot = Digraph()
22
+
23
+
dot.node('A', 'User submits form')
24
+
dot.node('B', 'HTML/JS form validation')
25
+
dot.node('C', 'Convert to Pydantic model')
26
+
dot.node('D', 'Optional custom validation')
27
+
dot.node('E', 'Update database')
28
+
dot.node('F', 'Middleware error handler')
29
+
dot.node('G', 'Render error template')
30
+
dot.node('H', 'Redirect to GET endpoint')
31
+
dot.node('I', 'Fetch updated data')
32
+
dot.node('J', 'Re-render Jinja2 page template')
33
+
34
+
dot.edge('A', 'B')
35
+
dot.edge('B', 'A')
36
+
dot.edge('B', 'C', label='POST Request to FastAPI endpoint')
The advantage of the PRG pattern is that it is very straightforward to implement and keeps most of the rendering logic on the server side. The disadvantage is that it requires an extra round trip to the database to fetch the updated data, and re-rendering the entire page template may be less efficient than a partial page update on the client side.
0 commit comments