Skip to main content

Methods

MethodAPI callReturns
publish(station)PUT /api/v1/station{ state }
updatePoints(points)PATCH /api/v1/station/points{ state }
heartbeat()POST /api/v1/station/heartbeatnothing
get()GET /api/v1/stationstored data + state
startHeartbeat(options?)heartbeat() every intervalMs (default 5 minutes)a stop function
metrics()nonethe station's Prometheus text exposition

publish replaces everything goodcharge knows about the station. updatePoints changes only the listed points; a point's position is its index in charging_points plus one.

startHeartbeat never throws once started, and never rejects: a failed beat is reported to onError (if given) instead, and a throwing onError is itself ignored, so a broken handler can't crash your process. An out-of-range intervalMs still throws invalid_option synchronously when you call startHeartbeat, before the first beat is scheduled. Call the returned function to stop.

Metrics helpers​

Exported from @goodcharge/sdk:

FunctionReturns
metricsText(stations)the text exposition for several stations
metricsHandler(stations)a (req, res) handler for Node.js http and Express; the list is fixed when you create it
metricsResponse(stations)a Response, for fetch-style frameworks

Also exported from @goodcharge/sdk:

  • METRICS_CONTENT_TYPE: the content type both helpers send, text/plain; version=0.0.4; charset=utf-8, for when you serve metricsText yourself.
  • MetricsResponseLike (type): the part of a Node.js ServerResponse or Express res that metricsHandler writes to: statusCode, setHeader(name, value) and end(body).

Exported from @goodcharge/sdk/prom-client: registerGoodchargeMetrics(registry, stations).

See Monitoring with Prometheus.