# FastAPI 类视图

> fastapi本身是没有类视图的概念的，实现类视图要借助 starlette.endpoints 下的 HTTPEndpoint 针对http请求
>
> WebSocketEndpoint 针对websocket

```python

from fastapi import FastAPI
from starlette.endpoints import HTTPEndpoint, WebSocketEndpoint
app = FastAPI()

class Test_HTTP(HTTPEndpoint):
    async def get(self, request: Request):
        return ''

    async def post(self, '其他参数'):
        return ''


# 这种方式添加的视图，没有docs和redoc文档
app.add_route('/test',Test_HTTP,name='aaa')


# 这个方法只能添加函数视图，因为底层是用fastapi的APIRoute创建的，只支持函数，也没有docs/redoc文档
app.add_api_route('/test2',func,name='bbb')  
```
