Exemplo n.º 1
0
def test_root_path() -> None:
    root_path = "/custom/root"
    parent_app = FastAPI()

    @parent_app.get("/check-root-path")
    def check_root_path(request: Request) -> Dict[str, Any]:
        return {"root_path": request.scope.get("root_path")}

    versioned_app = VersionedFastAPI(app=parent_app, root_path=root_path)
    test_client = TestClient(versioned_app, root_path=root_path)

    response = test_client.get("/v1_0/check-root-path")
    assert response.status_code == 200
    assert response.json() == {"root_path": "/custom/root/v1_0"}
Exemplo n.º 2
0
@version(1, 0)
async def add_sock(sock: NMEASocket) -> Any:
    await controller.add_sock(sock)


@app.delete(
    "/socks",
    status_code=status.HTTP_200_OK,
    summary="Remove existing NMEA socket.",
)
@version(1, 0)
def remove_sock(sock: NMEASocket) -> Any:
    controller.remove_sock(sock)


app = VersionedFastAPI(app, version="1.0.0", prefix_format="/v{major}.{minor}", enable_latest=True)


@app.get("/")
async def read_items() -> Any:
    html_content = """
    <html>
        <head>
            <title>NMEA Injector</title>
        </head>
    </html>
    """
    return HTMLResponse(content=html_content, status_code=200)


if __name__ == "__main__":
Exemplo n.º 3
0
from fastapi import FastAPI
from fastapi_versioning import VersionedFastAPI

from example.router import v1_0, v1_1

app = FastAPI()
app.include_router(v1_0.router)
app.include_router(v1_1.router)
app = VersionedFastAPI(app)
from fastapi import FastAPI
from fastapi_versioning import VersionedFastAPI
from starlette.middleware.cors import CORSMiddleware
from app.api.routers import api_router
from app.core.config import get_settings
from app.core.db import init_db

settings = get_settings()

app = FastAPI(title=settings.PROJECT_NAME)

app.include_router(api_router)
app = VersionedFastAPI(app,
                       version_format="{major}",
                       prefix_format="/api/v{major}")
init_db(app)
Exemplo n.º 5
0
Arquivo: main.py Projeto: yupix/ssm
custom_blogrole = config_ini['CUSTOM']['Blogrole']
use_api = config_ini['API']['use']
use_eew = config_ini['EEW']['use']

Dic_Path = config_ini['JTALK']['Dic_Path']
Voice_Path = config_ini['JTALK']['Voice_Path']
Jtalk_Bin_Path = config_ini['JTALK']['Jtalk_Bin_Path']
Output_wav_name = config_ini['JTALK']['Output_wav_name']
read_aloud = config_ini['JTALK']['read_aloud']
Speed = config_ini['JTALK']['Speed']
show_bot_chat_log = config_ini['OPTIONS']['show_bot_chat_log']

app = FastAPI(title=f'{bot_user} API')
app.include_router(v1.servers.router)
app = VersionedFastAPI(app,
                       version_format='{major}',
                       prefix_format='/v{major}')

INITIAL_EXTENSIONS = [
    'ssm.cogs.testcog',
    'ssm.cogs.note',
    'ssm.cogs.blocklist',
    'ssm.cogs.warframe',
    'ssm.cogs.pso2',
    'ssm.cogs.blog',
    'ssm.cogs.read',
    'ssm.cogs.basic',
    'ssm.cogs.eew',
]

Exemplo n.º 6
0
from fastapi import FastAPI

from fastapi_versioning import VersionedFastAPI, version

app = FastAPI(title="My Online Store")


@app.get("/")
def home() -> str:
    return "Hello default version 2.0!"


@app.get("/")
@version(3, 0)
def home_v3() -> str:
    return "Hello version 3.0!"


app = VersionedFastAPI(app, default_version=(2, 0))
Exemplo n.º 7
0
from fastapi import FastAPI

from fastapi_versioning import VersionedFastAPI, version

app = FastAPI(title="My App")


@app.get("/greet")
@version(1, 0)
def greet_with_hello() -> str:
    return "Hello"


@app.get("/greet")
@version(1, 1)
def greet_with_hi() -> str:
    return "Hi"


app = VersionedFastAPI(app, root_path="/api")
Exemplo n.º 8
0
fast_api_app = FastAPI(
    title="Helper API",
    description=
    "Everybody's helper to find web services that are running in companion.",
    default_response_class=PrettyJSONResponse,
)


@fast_api_app.get(
    "/web_services",
    response_model=List[ServiceInfo],
    summary="Retrieve web services found.",
)
@version(1, 0)
def web_services() -> Any:
    """REST API endpoint to retrieve web services running."""
    return Helper.scan_ports()


app = VersionedFastAPI(
    fast_api_app,
    version="1.0.0",
    prefix_format="/v{major}.{minor}",
    enable_latest=True,
)

app.mount("/", StaticFiles(directory=str(HTML_FOLDER), html=True))

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=PORT)
Exemplo n.º 9
0
from fastapi import FastAPI

from example.annotation import item, store
from fastapi_versioning import VersionedFastAPI

app = FastAPI(title="My Online Store")
app.include_router(store.router)
app.include_router(item.router)
app = VersionedFastAPI(app, enable_latest=True)
Exemplo n.º 10
0
# Serve static files
app_dir = Path(__file__).parent.resolve()
app.mount("/static",
          StaticFiles(directory=str(app_dir / "static")),
          name="static")

# API mounted under /api
original_api = FastAPI()
original_api.include_router(monitoring.router,
                            prefix="/-",
                            tags=["monitoring"])
original_api.include_router(login.router, tags=["login"])
original_api.include_router(users.router, prefix="/users", tags=["users"])
original_api.include_router(
    services.router,
    prefix="/services",
    tags=["services"],
)

versioned_api = VersionedFastAPI(
    original_api,
    version_format="{major}",
    prefix_format="/v{major}",
)

app.mount("/api", versioned_api)

if SENTRY_DSN:
    sentry_sdk.init(dsn=SENTRY_DSN, environment=ESS_NOTIFY_SERVER_ENVIRONMENT)
    app = SentryAsgiMiddleware(app)
Exemplo n.º 11
0
siibra_version_header = 'x-siibra-api-version'

# Main fastAPI application
app = FastAPI(title="Siibra API",
              description="This is the REST api for siibra tools",
              version="1.0",
              openapi_tags=tags_metadata)
# Add a siibra router with further endpoints
app.include_router(parcellation_router, prefix=ATLAS_PATH)
app.include_router(space_router, prefix=ATLAS_PATH)
app.include_router(atlas_router, prefix=ATLAS_PATH)
app.include_router(siibra_router)
app.include_router(health_router)

# Versioning for all api endpoints
app = VersionedFastAPI(app, default_api_version=1)

# Template list, with every template in the project
# can be rendered and returned
templates = Jinja2Templates(directory='templates/')
app.mount("/static", StaticFiles(directory="static"), name="static")

pypi_stat_url = 'https://pypistats.org/api/packages/siibra/overall?mirrors=false'

# Allow CORS
origins = ['*']
app.add_middleware(CORSMiddleware,
                   allow_origins=origins,
                   allow_methods=['GET'],
                   expose_headers=[siibra_version_header])