CampaignFlow.MockServer.Handlers.Helpers (CampaignFlow Client v2.2.0)

View Source

Shared helpers for mock server HTTP handlers: bearer auth, integer path-param parsing, and the like. Keeps individual handler modules free of boilerplate.

Summary

Functions

Parses a path-param string as an integer. Returns {:ok, int} for a fully-numeric value, :error otherwise.

Wraps a handler function with a bearer-auth check. The function is invoked only if the request has a non-empty Authorization: Bearer ... header; otherwise a 401 is sent.

Functions

parse_id(id)

@spec parse_id(String.t()) :: {:ok, integer()} | :error

Parses a path-param string as an integer. Returns {:ok, int} for a fully-numeric value, :error otherwise.

with_auth(conn, fun)

@spec with_auth(Plug.Conn.t(), (-> Plug.Conn.t())) :: Plug.Conn.t()

Wraps a handler function with a bearer-auth check. The function is invoked only if the request has a non-empty Authorization: Bearer ... header; otherwise a 401 is sent.