mirror of
https://github.com/fastapi/fastapi.git
synced 2026-01-01 02:29:46 -05:00
* 🌐 Refactor file structure to support internationalization * ✅ Update tests changed after i18n * 🔀 Merge Typer style from master * 🔧 Update MkConfig with Typer-styles * 🎨 Format mkdocs.yml with cannonical form * 🎨 Format mkdocs.yml * 🔧 Update MkDocs config * ➕ Add docs translation scripts dependencies * ✨ Add Typer scripts to handle translations * ✨ Add missing translation snippet to include * ✨ Update contributing docs, add docs for translations * 🙈 Add docs_build to gitignore * 🔧 Update scripts with new locations and docs scripts * 👷 Update docs deploy action with translations * 📝 Add note about languages not supported in the theme * ✨ Add first translation, for Spanish
53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
from fastapi import APIRouter, FastAPI
|
|
from fastapi.responses import JSONResponse
|
|
from pydantic import BaseModel, HttpUrl
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
class Invoice(BaseModel):
|
|
id: str
|
|
title: str = None
|
|
customer: str
|
|
total: float
|
|
|
|
|
|
class InvoiceEvent(BaseModel):
|
|
description: str
|
|
paid: bool
|
|
|
|
|
|
class InvoiceEventReceived(BaseModel):
|
|
ok: bool
|
|
|
|
|
|
invoices_callback_router = APIRouter(default_response_class=JSONResponse)
|
|
|
|
|
|
@invoices_callback_router.post(
|
|
"{$callback_url}/invoices/{$request.body.id}", response_model=InvoiceEventReceived,
|
|
)
|
|
def invoice_notification(body: InvoiceEvent):
|
|
pass
|
|
|
|
|
|
@app.post("/invoices/", callbacks=invoices_callback_router.routes)
|
|
def create_invoice(invoice: Invoice, callback_url: HttpUrl = None):
|
|
"""
|
|
Create an invoice.
|
|
|
|
This will (let's imagine) let the API user (some external developer) create an
|
|
invoice.
|
|
|
|
And this path operation will:
|
|
|
|
* Send the invoice to the client.
|
|
* Collect the money from the client.
|
|
* Send a notification back to the API user (the external developer), as a callback.
|
|
* At this point is that the API will somehow send a POST request to the
|
|
external API with the notification of the invoice event
|
|
(e.g. "payment successful").
|
|
"""
|
|
# Send the invoice, collect the money, send the notification (the callback)
|
|
return {"msg": "Invoice received"}
|