fixed dockerfile, added fastapi
This commit is contained in:
40
src/app.py
Normal file
40
src/app.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from collections.abc import AsyncIterator
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import Response
|
||||
|
||||
from fastapi_cache import FastAPICache
|
||||
from fastapi_cache.backends.redis import RedisBackend
|
||||
from fastapi_cache.decorator import cache
|
||||
|
||||
from redis import asyncio as aioredis
|
||||
from openbabel import pybel
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(_: FastAPI) -> AsyncIterator[None]:
|
||||
redis = aioredis.from_url("redis://localhost")
|
||||
FastAPICache.init(RedisBackend(redis), prefix="fastapi-cache")
|
||||
yield
|
||||
|
||||
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
|
||||
|
||||
@app.get("/informats")
|
||||
async def get_informats():
|
||||
return pybel.informats
|
||||
|
||||
|
||||
@app.get("/")
|
||||
@cache(expire=60)
|
||||
async def index():
|
||||
return dict(hello="world")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user