Skip to content

Commit

Permalink
init code
Browse files Browse the repository at this point in the history
Signed-off-by: samzong.lu <[email protected]>
  • Loading branch information
samzong committed May 17, 2024
1 parent ddc8d98 commit a039152
Show file tree
Hide file tree
Showing 17 changed files with 265 additions and 267 deletions.
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

14 changes: 0 additions & 14 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/markdown.xml

This file was deleted.

4 changes: 0 additions & 4 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/user_example.iml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ludotech/python3.9-poetry
FROM python:3.11-slim

LABEL maintainer="[email protected]"

Expand Down
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
# FastAPI-started-Example

craeted by [email protected]

- base one file on main.py
- split api to api/users.py `git checkout Split-project-file`
# pyproject teamplete
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Title: README.md
78 changes: 12 additions & 66 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,23 @@
"""

from fastapi import FastAPI, Path, Query
from pydantic import BaseModel
from typing import Optional, List
import uvicorn
from fastapi import FastAPI

tags_metadata = [
{
"name": "users",
"description": "Operations with users. The **login** logic is also here.",
},
{
"name": "items",
"description": "Manage items. So _fancy_ they have their own docs.",
"externalDocs": {
"description": "Items external docs",
"url": "https://fastapi.tiangolo.com/",
},
},
]
from src.hello import hello

app = FastAPI(
openapi_url="/api/v1/openapi.json",
docs_url="/documentation",
docs_url="/docs",
redoc_url=None,
openapi_tags=tags_metadata,
title="user example",
description="A demo project of user example",
title="Template Project",
description="A template project of FastAPI",
version="1.0",
terms_of_service="https://samzong.me",
contact={
"name": "Alex",
"name": "Samzong Lu",
"url": "https://samzong.me",
"email": "samzong.lu@gmail.com"
"email": "samzonglu@gmail.com"
},
license_info={
"name": "Apache 2.0",
Expand All @@ -49,49 +34,10 @@
)


class User(BaseModel):
# user_id: int
user_name: str
email: str
age: int
is_active: bool
bio: Optional[str]


users = []


@app.get("/")
async def homepage():
return {"Hello": "World"}


@app.get("/users", response_model=List[User], tags=["users"])
async def get_users():
return users


@app.post("/users", tags=["users", "items"])
async def create_user(user: User):
users.append(user)
return "Success"


@app.get("/users/{id}", tags=["users"],
summary="This is summary",
response_description="This is a response_description")
async def get_user(
id: int = Path(..., description="The ID of the user you want to get", gt=1),
q: str = Query(None, max_length=6)
):
return {"user": users[id], "q": q}
async def index():
return hello()


@app.delete("/user/{id}", tags=["items"], deprecated=True)
async def delete_user(id: int = Path(..., description="The ID of the user is you want remove it")):
"""
- This line 1
- This line 2
"""
users.pop(id)
return "Success"
if __name__ == '__main__':
uvicorn.run(app, host="0.0.0.0", port=8000, log_level="info")
Loading

0 comments on commit a039152

Please sign in to comment.