Certainly! Below is a simple example of a FastAPI app for a wedding website. This app includes basic endpoints for:
- Viewing wedding details (date, venue, couple names)
- RSVP submission
- Viewing the guest list (for admin or public, depending on your needs)
You can expand this with templates, databases, authentication, etc., but this is a good starting point.
Step 1: Install FastAPI and Uvicorn
pip install fastapi uvicorn
Step 2: Create the FastAPI app (main.py)
from fastapi import FastAPI, HTTPException, Form
from pydantic import BaseModel, EmailStr
from typing import List
app = FastAPI(title="Wedding API")
# In-memory storage for RSVPs (replace with DB in production)
rsvps = []
# Wedding details
wedding_info = {
"couple": "Alice & Bob",
"date": "2025-09-15",
"venue": "Sunset Beach Resort",
"address": "123 Ocean Drive, Paradise City",
"time": "4:00 PM"
}
class RSVP(BaseModel):
name: str
email: EmailStr
attending: bool
guests: int = 0 # number of additional guests
@app.get("/")
def read_root():
return {"message": "Welcome to Alice & Bob's Wedding API!"}
@app.get("/wedding")
def get_wedding_info():
return wedding_info
@app.post("/rsvp")
def submit_rsvp(rsvp: RSVP):
# Check if already RSVP'd
for existing in rsvps:
if existing['email'] == rsvp.email:
raise HTTPException(status_code=400, detail="RSVP already submitted for this email.")
rsvps.append(rsvp.dict())
return {"message": "Thank you for your RSVP!", "rsvp": rsvp}
@app.get("/rsvps", response_model=List[RSVP])
def get_rsvps():
# In real app, protect this endpoint with authentication
return rsvps
Step 3: Run the app
uvicorn main:app --reload
How to use:
- GET
/wedding — Get wedding details.
- POST
/rsvp — Submit RSVP with JSON body like:
{
"name": "John Doe",
"email": "john@example.com",
"attending": true,
"guests": 2
}
- GET
/rsvps — View all RSVPs (for admin).
Optional: Simple HTML form for RSVP (using FastAPI's Form)
If you want a simple HTML form to submit RSVP, you can add:
from fastapi.responses import HTMLResponse
from fastapi import Request
@app.get("/rsvp-form", response_class=HTMLResponse)
def rsvp_form():
return """
<html>
<body>
<h2>RSVP to Alice & Bob's Wedding</h2>
<form action="/rsvp-submit" method="post">
Name: <input type="text" name="name"><br>
Email: <input type="email" name="email"><br>
Attending:
<select name="attending">
<option value="true">Yes</option>
<option value="false">No</option>
</select><br>
Number of additional guests: <input type="number" name="guests" value="0"><br>
<input type="submit" value="Submit RSVP">
</form>
</body>
</html>
"""
@app.post("/rsvp-submit")
def rsvp_submit(
name: str = Form(...),
email: EmailStr = Form(...),
attending: str = Form(...),
guests: int = Form(0)
):
attending_bool = attending.lower() == "true"
rsvp = RSVP(name=name, email=email, attending=attending_bool, guests=guests)
# Check if already RSVP'd
for existing in rsvps:
if existing['email'] == rsvp.email:
raise HTTPException(status_code=400, detail="RSVP already submitted for this email.")
rsvps.append(rsvp.dict())
return {"message": "Thank you for your RSVP!", "rsvp": rsvp}
This is a minimal but functional FastAPI wedding app. Let me know if you want me to add database support, authentication, or a frontend!