File tree Expand file tree Collapse file tree 6 files changed +77
-0
lines changed Expand file tree Collapse file tree 6 files changed +77
-0
lines changed Original file line number Diff line number Diff line change 1+ """REST API service based on FastAPI."""
Original file line number Diff line number Diff line change 1+ """Handler for REST API call to provide info."""
2+
3+ import asyncio
4+ import logging
5+ from typing import Any , Optional
6+
7+ from fastapi import APIRouter , Request
8+
9+ logger = logging .getLogger (__name__ )
10+ router = APIRouter (tags = ["info" ])
11+
12+
13+ @router .get ("/info" )
14+ def info_endpoint_handler (request : Request ) -> dict :
15+ return {
16+ "foo" : 1 ,
17+ "bar" : 2 ,
18+ }
Original file line number Diff line number Diff line change 1+ from fastapi import FastAPI , Request , Response
2+ from app import routers
3+ import version
4+
5+ app = FastAPI (
6+ title = "Swagger service - OpenAPI" ,
7+ description = f" service API specification." ,
8+ version = version .__version__ ,
9+ license_info = {
10+ "name" : "Apache 2.0" ,
11+ "url" : "https://www.apache.org/licenses/LICENSE-2.0.html" ,
12+ },
13+ )
14+
15+ routers .include_routers (app )
Original file line number Diff line number Diff line change 1+ """REST API routers."""
2+
3+ from fastapi import FastAPI
4+
5+ from app .endpoints import (
6+ info ,
7+ )
8+
9+
10+ def include_routers (app : FastAPI ) -> None :
11+ """Include FastAPI routers for different endpoints.
12+
13+ Args:
14+ app: The `FastAPI` app instance.
15+ """
16+ app .include_router (info .router , prefix = "/v1" )
Original file line number Diff line number Diff line change 1+ """Uvicorn runner."""
2+
3+ import logging
4+
5+ import uvicorn
6+
7+ logger : logging .Logger = logging .getLogger (__name__ )
8+
9+
10+ def start_uvicorn () -> None :
11+ """Start Uvicorn-based REST API service."""
12+ logger .info ("Starting Uvicorn" )
13+
14+ host = "localhost"
15+ port = 8080
16+ workers = 1
17+
18+ uvicorn .run (
19+ "app.main:app" ,
20+ host = host ,
21+ port = port ,
22+ workers = workers ,
23+ )
Original file line number Diff line number Diff line change 1+ """Service version that is read by project manager tools."""
2+
3+ # this should be the only version value used in all source codes!!!
4+ __version__ = "0.0.1"
You can’t perform that action at this time.
0 commit comments