How punkystone/iobroker-history-api works
Purpose and Entry Point
This Go service exposes a narrow HTTP façade over ioBroker chart-history retrieval. The process starts in cmd/api/main.go, which loads environment-driven configuration, constructs the history client and HTTP server, then serves POST /history.
Runtime and Deployment
The application runs as a Go HTTP process and is intended to be containerized. Dockerfile defines the service image; docker-compose.yml supports local/container deployment. Runtime connection details come from environment variables via internal/env/env.go, notably the ioBroker socket.io endpoint, datasource instance, and debug mode.
HTTP API Boundary
internal/server/server.go owns HTTP routing and request/response orchestration for /history. It accepts JSON containing chart ID, time range, and requested value count; only POST is valid. HTTP-specific decoding, validation/error writing, and JSON response handling are separated into internal/server/http_utils.go.
History Integration
internal/history/history.go is the external-system adapter. It connects to the configured ioBroker socket.io service and issues the history lookup against the selected ioBroker datasource instance (for example, InfluxDB). It converts the remote response into timestamp/value history points returned by the API.
Primary Request Flow
1. cmd/api/main.go initializes configuration from internal/env/env.go.
2. It wires the ioBroker-backed history capability from internal/history/history.go into the HTTP server in internal/server/server.go.
3. A client POSTs /history; server code parses the JSON request and enforces method/body constraints.
4. The server delegates the lookup across the history adapter boundary to ioBroker socket.io.
5. The adapter returns points or an integration error; the server serializes either the success envelope or a 400/405 HTTP error.
Key Boundaries and Failure Semantics
The server layer isolates public HTTP behavior from ioBroker protocol details: callers do not connect to socket.io directly. Configuration isolates deployment-specific host and datasource selection. Invalid JSON and failed history lookups are surfaced as 400 Bad Request; unsupported methods are 405 Method Not Allowed. Debug logging of sent/received integration messages is controlled through environment configuration.
Components 10
Service Runtime
- Service image
Dockerfile - Local deployment
docker-compose.yml - API entry point · Builds configuration, history client, and HTTP server.
cmd/api/main.go - Runtime configuration · Reads socket.io endpoint, datasource instance, and debug mode.
internal/env/env.go
HTTP API
- History HTTP server · Owns POST /history orchestration.
internal/server/server.go - HTTP JSON handling · Decodes requests and writes JSON errors and responses.
internal/server/http_utils.go
History Integration
- ioBroker history client · Queries the selected ioBroker history datasource.
internal/history/history.go
Other components
- API client
- ioBroker socket.io
- History datasource · Selected datasource, such as InfluxDB.
Connections 12
- Service image → API entry point: packages
- Local deployment → Service image: runs image
- API entry point → Runtime configuration: loads
- API entry point → ioBroker history client: configures
- API entry point → History HTTP server: wires
- Runtime configuration → ioBroker history client: endpoint, datasource, debug
- API client → History HTTP server: POST /history
- History HTTP server → HTTP JSON handling: decode and serialize
- History HTTP server → ioBroker history client: history lookup
- ioBroker history client → ioBroker socket.io: socket.io request
- ioBroker socket.io → History datasource: queries
- History HTTP server → API client: points or 400/405