add python project and remove express projec
This commit is contained in:
1
fastapi-python/.gitignore
vendored
Normal file
1
fastapi-python/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
__pycache__/
|
||||
6
fastapi-python/README.md
Normal file
6
fastapi-python/README.md
Normal file
@ -0,0 +1,6 @@
|
||||
# Get started
|
||||
|
||||
```sh
|
||||
|
||||
fastapi dev main.py
|
||||
```
|
||||
29
fastapi-python/main.py
Normal file
29
fastapi-python/main.py
Normal file
@ -0,0 +1,29 @@
|
||||
from typing import Union
|
||||
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
|
||||
class Transfer(BaseModel):
|
||||
amount: int
|
||||
sender: int
|
||||
receiver: int
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
accounts = {
|
||||
'1': {'amount': 1000},
|
||||
'2': {'amount': 1000},
|
||||
}
|
||||
|
||||
@app.post("/transfer")
|
||||
def transfer(transfer: Transfer):
|
||||
amount = transfer.amount
|
||||
sender = transfer.sender
|
||||
receiver = transfer.receive
|
||||
|
||||
if amount <= 0:
|
||||
return {"error": "Amount must be greater than 0"}
|
||||
|
||||
print(f"transfer {amount} from {sender} to {receiver}")
|
||||
|
||||
return {"amount": amount, "sender": sender, "receiver": receiver}
|
||||
Reference in New Issue
Block a user