mud_server.admin_gradio.api.base

Base API Client for MUD Server.

This module provides the foundational HTTP client for communicating with the FastAPI backend server. It handles common patterns like request execution, error handling, and response parsing.

All domain-specific API clients (auth, game, admin, ollama) inherit from BaseAPIClient to get consistent error handling and request patterns.

Configuration:

SERVER_URL: Backend API server URL (can be overridden with MUD_SERVER_URL env var)

Classes

BaseAPIClient

Base API client providing common HTTP request patterns and error handling.

Module Contents

class mud_server.admin_gradio.api.base.BaseAPIClient(server_url=None)[source]

Base API client providing common HTTP request patterns and error handling.

This class handles: - Server URL configuration - Common request patterns (GET, POST) - Consistent error handling and formatting - Response parsing and validation

server_url

Backend API server URL

Initialize the base API client.

Parameters:

server_url (str | None) – Optional server URL override. If not provided, uses MUD_SERVER_URL environment variable or defaults to http://localhost:8000

server_url
get(endpoint, params=None, headers=None, timeout=30)[source]

Make a GET request to the API.

Parameters:
  • endpoint (str) – API endpoint path

  • params (dict | None) – Optional query parameters

  • headers (dict[str, str] | None) – Optional headers to send with the request

  • timeout (int) – Request timeout in seconds

Returns:

Standardized response dictionary (see _make_request)

Return type:

dict[str, Any]

post(endpoint, json=None, headers=None, timeout=30)[source]

Make a POST request to the API.

Parameters:
  • endpoint (str) – API endpoint path

  • json (dict | None) – Optional JSON body

  • headers (dict[str, str] | None) – Optional headers to send with the request

  • timeout (int) – Request timeout in seconds

Returns:

Standardized response dictionary (see _make_request)

Return type:

dict[str, Any]