-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
41 lines (29 loc) · 827 Bytes
/
main.py
File metadata and controls
41 lines (29 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
class Personne(BaseModel):
nom: str
age: int
app = FastAPI()
personnes = []
@app.get("/")
async def root():
return {"message": "Hello World"}
@app.get("/personnes")
async def all():
return personnes
@app.get("/personnes/{nom}")
async def get_personne(nom):
for p in personnes:
if p.nom == nom:
return p
raise HTTPException(status_code=404, detail="Item not found")
@app.post("/personnes")
async def create_personne(p: Personne):
wasFound = False
for x in personnes:
if x.nom == p.nom:
wasFound = True
if wasFound == False:
personnes.append(p)
return f"La liste a maintenant {len(personnes)} objet(s) de type Personne"
## Ajoutez l'opération Delete