Users Path Operations¶
Code¶
main.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/users/")
def read_users():
return [{"username": "Rick"}, {"username": "Morty"}]
@app.get("/users/{user_id}")
def read_user(user_id: int):
return {"id": user_id, "username": "Pickle Rick"}
Server¶
Run the live server:
$ uvicorn main:app --reload
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
<span style="color: green;">INFO</span>: Started reloader process [28720]
<span style="color: green;">INFO</span>: Started server process [28722]
<span style="color: green;">INFO</span>: Waiting for application startup.
<span style="color: green;">INFO</span>: Application startup complete.
API docs¶
Now you can open the API docs UI at: http://127.0.0.1:8000/docs.