Coverage for docs_src/openapi_webhooks/tutorial001.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-12-04 08:29 +0000

1from datetime import datetime 1abcdefg

2 

3from fastapi import FastAPI 1abcdefg

4from pydantic import BaseModel 1abcdefg

5 

6app = FastAPI() 1abcdefg

7 

8 

9class Subscription(BaseModel): 1abcdefg

10 username: str 1abcdefg

11 monthly_fee: float 1abcdefg

12 start_date: datetime 1abcdefg

13 

14 

15@app.webhooks.post("new-subscription") 1abchdiejfkgl

16def new_subscription(body: Subscription): 1abcdefg

17 """ 

18 When a new user subscribes to your service we'll send you a POST request with this 

19 data to the URL that you register for the event `new-subscription` in the dashboard. 

20 """ 

21 

22 

23@app.get("/users/") 1abcdefg

24def read_users(): 1abcdefg

25 return ["Rick", "Morty"] 1mnopqrs