The SndAPI class provides a programmatic interface to the Sales & Dungeon API. It is automatically generated from the API definition.
Initialization
To use the SDK, initialize the SndAPI class with the base_url of your API instance. A common default is http://127.0.0.1:7123.
API Methods
Methods are generated based on the API endpoints. Each method performs a POST request to an api/ endpoint and returns the JSON response.
Data Types
The SDK maps Go/SND types to Python types as follows:
string $\rightarrow$ strint $\rightarrow$ intfloat $\rightarrow$ floatbool $\rightarrow$ boolmap or interface {} $\rightarrow$ dict[]T (slices) $\rightarrow$ list of Tsnd.TypeName $\rightarrow$ dict [snd type type_name]
import requests
# Example of how the generated SDK is structured
class SndAPI:
def __init__(self, base_url):
"""
Initialize the Sales & Dungeon API class with the base URL of the API.
Parameters:
- base_url (str): The base URL of the API. Most likely "http://127.0.0.1:7123"
"""
self.base_url = base_url
def _make_request(self, endpoint, method='GET', params=None):
url = f"{self.base_url}/{endpoint}"
if method == 'GET':
response = requests.get(url, params=params)
elif method == 'POST':
response = requests.post(url, json=params)
elif method == 'DELETE':
response = requests.delete(url, json=params)
else:
raise ValueError(f"Unsupported HTTP method: {method}")
if response.status_code == 200:
return response.json()
else:
response.raise_for_status()
# Example of a generated method
def example_action(self, arg0, arg1):
"""
Perform an action using the example_action API endpoint.
Parameters:
- arg0 (str): parameter
- arg1 (int): parameter
"""
endpoint = "api/example_action"
return self._make_request(endpoint, method='POST', params=[arg0, arg1])