Monitorex.Api
(monitorex v0.6.0)
Copy Markdown
Response helpers and shared utilities for the Monitorex REST API.
Provides consistent JSON envelopes, CORS headers, pagination, and
filter parsing used by Monitorex.ApiPlug.
Summary
Functions
Converts a percentage to a float or returns nil.
Converts an Event struct to a safe API map, removing internal fields.
Sends an error response.
Sends a success response with the given data.
Builds pagination headers for a result set. Returns a list of header tuples.
Parses common query parameters into storage options.
Sets CORS headers for cross-origin access.
Functions
Converts a percentage to a float or returns nil.
@spec event_to_api(Monitorex.Event.t()) :: map()
Converts an Event struct to a safe API map, removing internal fields.
@spec json_error(Plug.Conn.t(), String.t(), integer()) :: Plug.Conn.t()
Sends an error response.
Envelope: {"ok": false, "error": message}
@spec json_ok(Plug.Conn.t(), term(), keyword()) :: Plug.Conn.t()
Sends a success response with the given data.
Envelope: {"ok": true, "data": ...}
Builds pagination headers for a result set. Returns a list of header tuples.
Parses common query parameters into storage options.
Supports:
limit— max results (default: 50, max: 500)offset— pagination offset (default: 0)status— numeric HTTP status code filterstatus_class— status class atom (:success, :error, :client_error, :server_error, :redirect)host— host filter (for outbound events)method— HTTP method filterconsumer— consumer filter (for inbound events)route— route key filter (for inbound events)direction— "outbound" or "inbound"since— ISO 8601 timestamp (filters events after this time, in epoch microseconds)
@spec set_cors(Plug.Conn.t()) :: Plug.Conn.t()
Sets CORS headers for cross-origin access.