Bloccs.Effects.HTTP behaviour (bloccs v0.1.1)

Copy Markdown View Source

HTTP effect facade + backend behaviour.

A node's effect-shell calls Bloccs.Effects.HTTP.post/3 / get/2 against the capability struct in ctx.effects.http. The facade dispatches to whichever backend built that struct — Bloccs.Effects.HTTP.Mock in tests, Bloccs.Effects.HTTP.Req in production — so node source never names a concrete backend. Backends @behaviour Bloccs.Effects.HTTP.

Allowlist/method enforcement is the backend's responsibility (every shipped backend enforces it before doing I/O); the facade is pure dispatch.

Summary

Types

A backend capability struct (e.g. %HTTP.Mock{} / %HTTP.Req{}).

A [effects].http declaration: allowed hosts + methods.

Functions

GET url through the bound HTTP backend.

POST body to url through the bound HTTP backend.

Types

cap()

@type cap() :: struct()

A backend capability struct (e.g. %HTTP.Mock{} / %HTTP.Req{}).

declaration()

@type declaration() :: %{allow: [String.t()], methods: [String.t()]}

A [effects].http declaration: allowed hosts + methods.

response()

@type response() :: {:ok, map()} | {:error, term()}

Callbacks

get(cap, t)

@callback get(cap(), String.t()) :: response()

new(declaration)

@callback new(declaration()) :: cap()

post(cap, t, term)

@callback post(cap(), String.t(), term()) :: response()

Functions

get(cap, url)

@spec get(cap(), String.t()) :: response()

GET url through the bound HTTP backend.

post(cap, url, body)

@spec post(cap(), String.t(), term()) :: response()

POST body to url through the bound HTTP backend.