flix

0.70.0

Net.Http

eff HttpSource

The effect used to send HTTP requests (both http:// and https://).

Operations

def request(req: HttpRequest): Result[IoError, HttpResponse] \ Http Source

Definitions

def delete(url: String): Result[IoError, HttpResponse] \ Http Source

Sends a DELETE request to the given url.

def get(url: String): Result[IoError, HttpResponse] \ Http Source

Sends a GET request to the given url.

def handle(f: a -> b \ ef): a -> b \ (ef - Http) + IO Source

Handles the Http effect of the given function f.

Re-interprets the Http effect using the IO effect.

def head(url: String): Result[IoError, HttpResponse] \ Http Source

Sends a HEAD request to the given url.

def options(url: String): Result[IoError, HttpResponse] \ Http Source

Sends an OPTIONS request to the given url.

def patch(url: String, body: String): Result[IoError, HttpResponse] \ Http Source

Sends a PATCH request to the given url with the given body.

def post(url: String, body: String): Result[IoError, HttpResponse] \ Http Source

Sends a POST request to the given url with the given body.

def put(url: String, body: String): Result[IoError, HttpResponse] \ Http Source

Sends a PUT request to the given url with the given body.

@DefaultHandler
def runWithIO(f: Unit -> a \ ef): a \ (ef - Http) + IO Source

Runs the Http effect of the given function f.

Re-interprets the Http effect using the IO effect.

def send(req: HttpRequest): Result[IoError, HttpResponse] \ Http Source

Sends the given request req via the Http effect.

def withBaseUrl(base: String, f: Unit -> a \ ef): a \ (ef - Http) + Http Source

Middleware that intercepts the Http effect, prepending base to request URLs that do not already start with a scheme. Absolute URLs (where "://" appears before the first "/") are left unchanged.

def withCircuitBreaker(ft: { failureThreshold = Int32 }, cdm: { cooldown = Duration }, f: Unit -> a \ ef): a \ (ef - Http) + Clock + Http Source

Middleware that intercepts the Http effect, implementing a circuit breaker.

Tracks consecutive failures (transport errors and 5xx server errors). After failureThreshold consecutive failures, the circuit opens and immediately rejects requests for cooldown. After the cooldown, one probe request is allowed through (half-open state). A successful probe closes the circuit; a failed probe restarts the cooldown.

Non-failure responses (2xx, 3xx, 4xx) reset the failure counter.

def withDefaultHeaders(defaults: Map[String, List[String]], f: Unit -> a \ ef): a \ (ef - Http) + Http Source

Middleware that intercepts the Http effect, injecting default headers into every request. Headers already present on the request are not overridden.

def withLogging(f: Unit -> a \ ef): a \ (ef - Http) + Http + Logger Source

Middleware that intercepts the Http effect, logging each request and its corresponding response via the Logger effect at Debug level.

def withMinInterval(ims: { interval = Duration }, f: Unit -> a \ ef): a \ (ef - Http) + Clock + Http Source

Middleware that intercepts the Http effect, enforcing a minimum interval between consecutive HTTP requests.

def withRetry(strategy: Int32 -> (HttpRequest -> (RetryOutcome -> RetryDecision \ ef1)), f: Unit -> a \ ef2): a \ ef1 + (ef2 - Http) + Http Source

Middleware that intercepts the Http effect, adding retry logic.

The strategy function decides whether to retry and how long to wait. Each Http.request is re-raised to an outer Http handler that performs the actual I/O.

def withSlidingWindow(mr: { maxRequests = Int32 }, wms: { window = Duration }, f: Unit -> a \ ef): a \ (ef - Http) + Clock + Http Source

Middleware that intercepts the Http effect, enforcing a sliding-window rate limit. Allows at most maxRequests within any rolling window. When the limit is reached, sleeps until the oldest request expires.

def withTokenBucket(bs: { burstSize = Int32 }, ims: { interval = Duration }, f: Unit -> a \ ef): a \ (ef - Http) + Clock + Http Source

Middleware that intercepts the Http effect, enforcing a token-bucket rate limit. Allows an initial burst of burstSize requests, then sustains at 1 request per interval.