haive.games.api.general_api¶
General API system for all haive games.
from typing import Any This module provides a general-purpose API that automatically discovers all available games and creates endpoints for each one, with OpenAPI documentation and game selection capabilities.
Classes¶
Information about an available game. |
|
Request for creating a new game. |
|
General API system that discovers and manages all games. |
Functions¶
|
Create a general game API that discovers all games. |
Module Contents¶
- class haive.games.api.general_api.GameInfo(/, **data)¶
Bases:
pydantic.BaseModel
Information about an available game.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class haive.games.api.general_api.GameSelectionRequest(/, **data)¶
Bases:
pydantic.BaseModel
Request for creating a new game.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class haive.games.api.general_api.GeneralGameAPI(app, games_package='haive.games', route_prefix='/api/games', ws_route_prefix='/ws/games', exclude_games=None)¶
General API system that discovers and manages all games.
Initialize the general game API.
- haive.games.api.general_api.create_general_game_api(app=None, **kwargs)¶
Create a general game API that discovers all games.
- Parameters:
app (fastapi.FastAPI | None) – Optional FastAPI app (creates one if not provided)
**kwargs – Additional arguments for GeneralGameAPI
- Returns:
Tuple of (FastAPI app, GeneralGameAPI instance)
- Return type:
tuple[fastapi.FastAPI, GeneralGameAPI]
Examples
>>> app, game_api = create_general_game_api() >>> # Now you have endpoints for all games!