Skip to content

Commit

Permalink
fix: Remove duplicated parts
Browse files Browse the repository at this point in the history
  • Loading branch information
MintCat98 committed Feb 11, 2025
1 parent 02268b8 commit 04dc82f
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/ai/backend/common/api_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,23 +267,18 @@ def api_handler(handler: BaseHandler) -> ParsedRequestHandler:
1. Request Body:
@api_handler
@api_handler
# UserModel is a Pydantic model
async def handler(body: BodyParam[UserModel]):
# 'parsed' property gets pydantic model you defined
user = body.parsed
async def handler(body: BodyParam[UserModel]): # UserModel is a Pydantic model
user = body.parsed # 'parsed' property gets pydantic model you defined
# Response model should inherit BaseResponseModel
return APIResponse.build(status_code=200, response_model=YourResponseModel(user=user.id))
2. Query Parameters:
@api_handler
@api_handler
async def handler(query: QueryParam[QueryPathModel]):
parsed_query = query.parsed
return APIResponse.build(status_code=200, response_model=YourResponseModel(search=parsed_query.query))
3. Headers:
@api_handler
@api_handler
async def handler(headers: HeaderParam[HeaderModel]):
parsed_header = headers.parsed
Expand All @@ -308,13 +303,10 @@ def from_request(cls, request: web.Request) -> Self:
return cls(user_id=user_id)
@api_handler
@api_handler
# No generic, so no need to call 'parsed'
async def handler(auth: AuthMiddlewareParam):
async def handler(auth: AuthMiddlewareParam): # No generic, so no need to call 'parsed'
return APIResponse(status_code=200, response_model=YourResponseModel(author_name=auth.name))
6. Multiple Parameters:
@api_handler
@api_handler
async def handler(
user: BodyParam[UserModel], # body
Expand Down

0 comments on commit 04dc82f

Please sign in to comment.