Implementation:4thfever Cultivation world simulator Public Query API
| Knowledge Sources | |
|---|---|
| Domains | API_Design, Server |
| Last Updated | 2026-10-22 14:00 GMT |
Overview
Concrete tool for exposing read-only game state through a stable `/api/v1/query/*` REST API, provided by the Cultivation World Simulator external control API layer.
Description
The create_public_query_router factory function creates a FastAPI `APIRouter` with all v1 query endpoints. Each endpoint delegates to either a `query_service` object (preferred) or individual builder callables (legacy fallback). All responses are wrapped in `ok_response()`.
The router exposes 20+ GET endpoints covering: runtime status, world state, world map, map presets, current run config, events (paginated), rankings, sect relations, game data, avatar metadata, phenomena, sect territories, mortal overview, dynasty overview/detail, avatar overview, saves list, entity detail, deceased list, roleplay session, and world secrets.
Usage
Import and mount this router when:
- Server setup: `main.py` creates the router with a `query_service` and mounts it on the FastAPI app
- Testing: create the router with builder callables to test individual endpoints
Code Reference
Source Location
- Repository: cultivation-world-simulator
- File: src/server/api/public_v1/query.py
Signature
def create_public_query_router(
*,
query_service: Any | None = None,
build_runtime_status: Callable[[], dict] | None = None,
build_world_state: Callable[[], dict] | None = None,
build_world_map: Callable[[], dict] | None = None,
build_map_presets: Callable[..., dict] | None = None,
build_current_run: Callable[[], dict] | None = None,
build_events_page: Callable[..., dict] | None = None,
build_rankings: Callable[[], dict] | None = None,
build_sect_relations: Callable[[], dict] | None = None,
build_game_data: Callable[[], dict] | None = None,
build_avatar_adjust_options: Callable[[], dict] | None = None,
build_avatar_meta: Callable[[], dict] | None = None,
build_avatar_list: Callable[[], dict] | None = None,
build_phenomena: Callable[[], dict] | None = None,
build_sect_territories: Callable[[], dict] | None = None,
build_mortal_overview: Callable[[], dict] | None = None,
build_dynasty_overview: Callable[[], dict] | None = None,
build_dynasty_detail: Callable[[], dict] | None = None,
build_avatar_overview: Callable[[], dict] | None = None,
build_saves: Callable[[], dict] | None = None,
build_detail: Callable[..., dict] | None = None,
build_deceased_list: Callable[[], dict] | None = None,
build_roleplay_session: Callable[[], dict] | None = None,
build_world_secret_meta: Callable[[], dict] | None = None,
build_world_secret_overview: Callable[[], dict] | None = None,
) -> APIRouter:
Import
from src.server.api.public_v1.query import create_public_query_router
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| query_service | None | No | Service object with methods matching each endpoint (preferred) |
| build_* callables | None | No | Individual builder functions (legacy fallback) |
Outputs
| Name | Type | Description |
|---|---|---|
| return | APIRouter | FastAPI router with all GET /api/v1/query/* endpoints |
Key Endpoints
| Endpoint | Query Params | Description |
|---|---|---|
| GET /api/v1/query/runtime/status | — | Init status, phase, progress, pause state, roleplay session |
| GET /api/v1/query/world/state | — | Avatar list, recent events, phenomenon, world time |
| GET /api/v1/query/world/map | — | Map tiles, regions, POIs, render config |
| GET /api/v1/query/events | avatar_id, sect_id, major_scope, cursor, limit | Paginated events with cursor |
| GET /api/v1/query/detail | type, id | Entity detail (avatar/sect/region/poi) |
| GET /api/v1/query/rankings | — | Heaven/earth/human/sect rankings |
Usage Examples
Mount Query Router with Service
from fastapi import FastAPI
from src.server.api.public_v1.query import create_public_query_router
app = FastAPI()
query_router = create_public_query_router(query_service=query_service)
app.include_router(query_router)
Query Runtime Status (External Agent)
import requests
resp = requests.get("http://localhost:8000/api/v1/query/runtime/status")
data = resp.json()
# {"ok": true, "data": {"status": "complete", "is_paused": true, ...}}
Related Pages
Implements Principle
Required Environments
- Environment:4thfever_Cultivation_world_simulator_Python_Runtime_Environment
- Environment:4thfever_Cultivation_world_simulator_Docker_Deployment_Environment
- Environment:4thfever_Cultivation_world_simulator_Frontend_Build_Environment