FastAPI 内部调用路径
在实际的开发中呢,我们可能有些接口呢,不能对比进行开放,比如说我们内部的一些监控的接口,那么我们肯定想着如何在接口文档中进行屏蔽,那么我们看下应该如何实现呢。
include_in_schema=False ,不暴露,只内部 127.0.0.1 调用, 接口文档屏蔽接口
@app.get("/legacy/", include_in_schema=False)
def get_legacy_data(response: Response):
headers = {"X-Cat": "leizi", "Content-Language": "en-US"}
data = """<?xml version="1.0"?>
<shampoo>
<Header>
Apply shampoo here.
</Header>
<Body>
You'll have to use soap here.
</Body>r
</shampoo>
"""
response.set_cookie(key="message", value="hello")
return Response(content=data, media_type="application/xml",
headers=headers)
Last updated