Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/starfx/mdw/fetch.ts

A micro-mvc framework for react apps
Go to Latest
import * as starfx from "https://deno.land/x/starfx@v0.13.2/mdw/fetch.ts";

Functions

This middleware will retry failed Fetch request if response.ok is false. It accepts a backoff function to determine how long to continue retrying. The default is an exponential backoff backoffExp where the minimum is 1sec between attempts and it'll reach 4s between attempts at the end with a max of 5 attempts.

Automatically sets content-type to application/json when that header is not already present.

This middleware takes the ctx.response and sets ctx.json to the body representation requested. It uses the ctx.bodyType property to determine how to represent the body. The default is set to json which calls Response.json().

This middleware converts the name provided to createApi into url and method for the fetch request.

If there's a slug inside the ctx.name (which is the URL segement in this case) and there is not a corresponding truthy value in the payload, then that means the user has an empty value (e.g. empty string) which means we want to abort the fetch request.