随笔分类 -  FastAPI

摘要:import typing from fastapi import FastAPI, Response from fastapi.responses import JSONResponse from pydantic import BaseModel app = FastAPI() ''' pyda 阅读全文
posted @ 2023-03-25 17:25 LeoShi2020 阅读(109) 评论(0) 推荐(0)
摘要:import typing from fastapi import FastAPI, Response from fastapi.responses import JSONResponse from pydantic import BaseModel app = FastAPI() ''' 过滤响应 阅读全文
posted @ 2023-03-25 15:45 LeoShi2020 阅读(145) 评论(0) 推荐(0)
摘要:import typing from fastapi import FastAPI, Response from fastapi.responses import JSONResponse from pydantic import BaseModel app = FastAPI() ''' 响应模型 阅读全文
posted @ 2023-03-25 12:40 LeoShi2020 阅读(99) 评论(0) 推荐(0)
摘要:from fastapi import FastAPI, Response from fastapi.responses import JSONResponse from pydantic import BaseModel app = FastAPI() class User(BaseModel): 阅读全文
posted @ 2023-03-25 12:17 LeoShi2020 阅读(28) 评论(0) 推荐(0)
摘要:from fastapi import FastAPI, Response from fastapi.responses import JSONResponse from pydantic import BaseModel app = FastAPI() class User(BaseModel): 阅读全文
posted @ 2023-03-25 11:12 LeoShi2020 阅读(148) 评论(0) 推荐(0)
摘要:from fastapi import FastAPI,status from pydantic import BaseModel app = FastAPI() ''' 响应状态代码 status ''' class User(BaseModel): username : str password 阅读全文
posted @ 2023-03-24 11:30 LeoShi2020 阅读(27) 评论(0) 推荐(0)
摘要:import random from fastapi import FastAPI from pydantic import Field, BaseModel import typing app = FastAPI() ''' 请求体的每一个字段需要单独校验 name 长度最少3位 price 不少 阅读全文
posted @ 2023-03-24 10:51 LeoShi2020 阅读(29) 评论(0) 推荐(0)
摘要:from fastapi import FastAPI, Body from pydantic import BaseModel import typing app = FastAPI() ''' { "name": "book", "description": "python", "price": 阅读全文
posted @ 2023-03-24 00:43 LeoShi2020 阅读(29) 评论(0) 推荐(0)
摘要:from fastapi import FastAPI,Body app =FastAPI() ''' 使用方法同Path Query ''' @app.post("/login") def login( name :str = Body(min_length=3), age:int = Body( 阅读全文
posted @ 2023-03-24 00:17 LeoShi2020 阅读(65) 评论(0) 推荐(0)
摘要:from fastapi import FastAPI, Body from pydantic import BaseModel app = FastAPI() ''' 使用Body接收请求体数据 { "user": { "username": "Tom", "password": "1234657 阅读全文
posted @ 2023-03-24 00:05 LeoShi2020 阅读(381) 评论(0) 推荐(0)
摘要:from fastapi import FastAPI from pydantic import BaseModel app = FastAPI() ''' 创建继承BaseModel的类,定义模型user 路径函数中定义形参user,类型为User 通过对象user的属性获取字段的值 客户端使用P 阅读全文
posted @ 2023-03-23 23:29 LeoShi2020 阅读(114) 评论(0) 推荐(0)
摘要:# 查找文件路径 find / -name docs.py vi docs.py # swagger_js_url: str = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-bundle.js", swagger_js_url 阅读全文
posted @ 2023-03-23 22:38 LeoShi2020 阅读(574) 评论(1) 推荐(0)
摘要:import typing from fastapi import FastAPI,Header app = FastAPI() @app.get("/books") # 接收多个token def books(token :typing.List[str] = Header()): return 阅读全文
posted @ 2023-03-23 22:07 LeoShi2020 阅读(37) 评论(0) 推荐(0)
摘要:import typing from fastapi import FastAPI, Query app = FastAPI() ''' 查询参数使用Query校验 类似路由转换使用Path校验 物品名称最小3位,最大10位 default=None 参数为可选项,否则为必选项 default=.. 阅读全文
posted @ 2023-03-23 21:06 LeoShi2020 阅读(71) 评论(0) 推荐(0)
摘要:from fastapi import FastAPI, Query import typing app = FastAPI() ''' 查询多个参数值相同 ''' @app.get("/books") def books(book_id: typing.List[int] = Query()): 阅读全文
posted @ 2023-03-23 20:36 LeoShi2020 阅读(47) 评论(0) 推荐(0)
摘要:import typing from fastapi import FastAPI app = FastAPI() BOOKS = [ {"id": i, "title": f"book{i}"} for i in range(1, 11) ] ''' 查询参数的默认值 ''' @app.get(" 阅读全文
posted @ 2023-03-23 17:23 LeoShi2020 阅读(119) 评论(0) 推荐(0)
摘要:from fastapi import FastAPI,Path app = FastAPI() # Path校验 ''' 限制接口输入的数字大小限制 100-1000 限制字符串输入的字符数量 3-8位 ''' # deprecated 即将废弃 # include_in_schema 隐藏接口 阅读全文
posted @ 2023-03-23 16:40 LeoShi2020 阅读(43) 评论(0) 推荐(0)
摘要:from enum import Enum from fastapi import FastAPI app = FastAPI() # 路径参数枚举值 ''' 编程语言三种分类:python java go ''' # 继承str 枚举Enum class LangName(str, Enum): 阅读全文
posted @ 2023-03-23 12:35 LeoShi2020 阅读(197) 评论(0) 推荐(0)
摘要:from fastapi import FastAPI app= FastAPI() # 路径转换器 ''' - str 字符串 - int 数字 - float 浮点 - uuid 返回python中的uuid.UUID - path 文件路径包含多个/ ''' @app.get("/books/ 阅读全文
posted @ 2023-03-23 10:14 LeoShi2020 阅读(48) 评论(0) 推荐(0)
摘要:![](https://img2023.cnblogs.com/blog/1940615/202303/1940615-20230323090712489-1952166291.png) 阅读全文
posted @ 2023-03-23 09:07 LeoShi2020 阅读(31) 评论(0) 推荐(0)