/api/system/theme

GET POST

Read or update the custom theme configuration file for UI customization.

Description

The /api/system/theme endpoint manages the custom theme configuration file stored at Data/Themes/custom_theme.txt. This endpoint allows you to read the current theme settings (GET) or update them with new configuration (POST). The theme file can contain any text-based configuration for customizing the user interface, such as color schemes, font preferences, or layout settings.

💡 Use Cases

This endpoint is perfect for:

  • Loading custom theme settings on application startup
  • Allowing users to customize UI appearance
  • Storing theme preferences persistently
  • Synchronizing theme settings across sessions
  • Implementing light/dark mode toggling
  • Managing custom color schemes

HTTP Methods

GET

Retrieve the current theme configuration file contents.

POST

Update the theme configuration file with new content.

GET Request

Read the current theme configuration.

Parameters

No parameters required for GET requests.

GET Response

Returns a JSON object containing the theme file information.

Response Properties

success boolean
Always true for successful requests.
command string
Command name: "get-theme"
file string
Filename: "custom_theme.txt"
path string
Full file path (e.g., "Data/Themes/custom_theme.txt")
content string
The complete contents of the theme configuration file.
size integer
File size in bytes.
exists boolean
true if file existed before request, false if newly created with defaults.

GET Example Response

{
  "success": true,
  "command": "get-theme",
  "file": "custom_theme.txt",
  "path": "Data/Themes/custom_theme.txt",
  "content": "# Custom Theme Configuration\n# Add your theme settings here\n",
  "size": 68,
  "exists": false
}

POST Request

Update the theme configuration file with new content.

Request Body

Send the new theme configuration as the raw POST body. The content can be any text format (plain text, JSON, INI, etc.).

⚠️ Size Limit

The theme file has a maximum size limit of 8 KB (8,192 bytes). Requests exceeding this limit will be rejected with HTTP 413 (Payload Too Large).

POST Parameters

Parameter Location Required Description
(request body) Body Yes The new theme configuration content. Can be any text format. Maximum 8 KB.

POST Response

Returns a JSON object confirming the update.

Response Properties

success boolean
Always true for successful updates.
command string
Command name: "update-theme"
file string
Filename: "custom_theme.txt"
path string
Full file path where theme was saved.
bytes_written integer
Number of bytes successfully written to file.
message string
Success message: "Theme configuration updated successfully"

POST Example Response

{
  "success": true,
  "command": "update-theme",
  "file": "custom_theme.txt",
  "path": "Data/Themes/custom_theme.txt",
  "bytes_written": 250,
  "message": "Theme configuration updated successfully"
}

Error Responses

HTTP Code Scenario Response
400 Empty POST body {"error": true, "message": "Empty request body", "code": 400}
405 Invalid HTTP method (not GET or POST) {"error": true, "message": "Method not allowed (use GET or POST)", "code": 405}
413 POST body exceeds 8 KB limit {"error": true, "message": "Theme content too large (max 8KB)", "code": 413}
500 File I/O error (permissions, disk full, etc.) {"error": true, "message": "Failed to read/create theme file", "code": 500}

Code Examples

cURL - GET Theme

curl http://127.0.0.1:8080/api/system/theme

cURL - POST Theme (Plain Text)

curl -X POST \
  -H "Content-Type: text/plain" \
  -d "theme: dark
colors:
  primary: #3498db
  secondary: #2ecc71
  background: #2c3e50
font: Roboto" \
  http://127.0.0.1:8080/api/system/theme

cURL - POST Theme (JSON Format)

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{
  "theme": "dark",
  "colors": {
    "primary": "#3498db",
    "secondary": "#2ecc71",
    "background": "#2c3e50"
  },
  "font": "Roboto"
}' \
  http://127.0.0.1:8080/api/system/theme

JavaScript/Fetch - GET Theme

fetch('http://127.0.0.1:8080/api/system/theme')
  .then(response => response.json())
  .then(data => {
    console.log('Theme content:', data.content);
    console.log('File size:', data.size, 'bytes');
  })
  .catch(error => console.error('Error:', error));

JavaScript/Fetch - POST Theme

const themeConfig = `theme: dark
colors:
  primary: #3498db
  secondary: #2ecc71
  background: #2c3e50
font: Roboto`;

fetch('http://127.0.0.1:8080/api/system/theme', {
  method: 'POST',
  headers: {
    'Content-Type': 'text/plain'
  },
  body: themeConfig
})
  .then(response => response.json())
  .then(data => {
    console.log('Update successful:', data.message);
    console.log('Bytes written:', data.bytes_written);
  })
  .catch(error => console.error('Error:', error));

Python - GET Theme

import requests

response = requests.get('http://127.0.0.1:8080/api/system/theme')
data = response.json()

print(f"Theme content:\n{data['content']}")
print(f"File size: {data['size']} bytes")
print(f"File exists: {data['exists']}")

Python - POST Theme

import requests

theme_config = """theme: dark
colors:
  primary: #3498db
  secondary: #2ecc71
  background: #2c3e50
font: Roboto"""

response = requests.post(
    'http://127.0.0.1:8080/api/system/theme',
    data=theme_config,
    headers={'Content-Type': 'text/plain'}
)

data = response.json()
print(f"Update successful: {data['message']}")
print(f"Bytes written: {data['bytes_written']}")

Theme File Format

The theme configuration file supports any text-based format. Here are common approaches:

Option 1: YAML-Style (Recommended)

# Custom Theme Configuration
theme: dark
colors:
  primary: #3498db
  secondary: #2ecc71
  background: #2c3e50
  text: #ecf0f1
font:
  family: Roboto
  size: 14px
layout:
  sidebar_width: 250px
  header_height: 60px

Option 2: JSON Format

{
  "theme": "dark",
  "colors": {
    "primary": "#3498db",
    "secondary": "#2ecc71",
    "background": "#2c3e50",
    "text": "#ecf0f1"
  },
  "font": {
    "family": "Roboto",
    "size": "14px"
  },
  "layout": {
    "sidebar_width": "250px",
    "header_height": "60px"
  }
}

Option 3: INI/Properties Style

# Custom Theme Configuration
[theme]
mode=dark

[colors]
primary=#3498db
secondary=#2ecc71
background=#2c3e50
text=#ecf0f1

[font]
family=Roboto
size=14px

[layout]
sidebar_width=250px
header_height=60px

Security Considerations

  • Fixed File Path: The theme file is always stored at Data/Themes/custom_theme.txt. Users cannot specify arbitrary file paths, preventing directory traversal attacks.
  • Size Limit: The 8 KB maximum size prevents denial-of-service attacks through large file uploads.
  • No Execution: The theme file is read and returned as plain text only. No code execution occurs.
  • Text Only: Only text-based content is supported. Binary files are not processed.

Best Practices

  • Version Control: Consider adding a version field to your theme configuration for easier management.
  • Comments: Use comments (# for YAML/INI, // for JSON-like) to document your theme settings.
  • Validation: Validate theme content on the client side before sending to ensure correct format.
  • Backup: Store a backup of your theme configuration before making changes.
  • Size Awareness: Monitor theme file size to stay well under the 8 KB limit.
  • Default Values: Include default values in your application for when theme file doesn't exist or is invalid.

Related Endpoints